demerphq kicked off a discussion on blogs.perl.org of the hash APIs that Perl (and perl) provides. The discussion also has a parallel strand on nntp.perl.org.

In my interpretation, the discussion moved on from removing restricted and locked hashes towards realizing that restricted and/or locked hashes can get a different hash implementation in the backend than plain hashes and maybe even plain hashes can get different implementations. This makes me somewhat happy because I really like using locked hashes for DBI query results and don't really care for the (potential) performance overhead.

Other people see a benefit in removing the performance overhead incurred by supporting restricted hashes, which I don't know about. But as these people know more about the internals, I'm inclined to trust them on their judgement as well.

Allowing different implementations of hashes opens up the interesting question of if or how a hash can move from one implementation to another, and personally I expect that only to happen for explicit assignments:

use feature 'superfast_hashes'; my %hash_with_implementation_A = ( foo => 'bar' ); no feature 'superfast_hashes'; my %hash_with_implementation_B = %hash_with_implementation_A;

If you have an opinion either way on the features of locked / restricted hashes, consider participating in the discussion either on nntp.perl.org or blogs.perl.org

choroba points out more discussion on reddit r/perl.

Replies are listed 'Best First'.
Re: Are Restricted/Locked Hashes a Failed Experiment? (yes, like perltie, benchmark)
by Anonymous Monk on Feb 01, 2017 at 02:02 UTC

    I would say yes they are, just like perltie

    Where as perltie problem is performance, the lock_keys problem is promotion, just what is it for?

    I find this post very telling Re: Should we consider locked hashes a failed experiment? - nntp.perl.org

    If this discussion somehow leads to a faster perltie for xs modules, that would be good :)

    Maybe this sheds some light

    #!/usr/bin/perl -- use strict; use warnings; use Benchmark 'cmpthese'; use Hash::Util(); use Tie::Hash::FixedKeys (); our %fudge= ( 1,1,3,3 ); our %judge = ( 1,1,3,3 ); our %budge = ( 1,1,3,3 ); our %mudge = ( 1,1,3,3 ); Hash::Util::lock_keys(%fudge); tie %budge, 'Tie::Hash::FixedKeys', keys %budge; cmpthese( -3, { 'lock' => '$fudge{1}++; eval{$fudge{r}++}; ', 'die' => '$judge{1}++; eval{$judge{r}++;die}; ', 'fix' => '$budge{1}++; eval{$budge{r}++;}; ', 'fatal' => '$mudge{{1,1}->{1}}++; eval{use warnings FATAL => qw(u +ninitialized); $mudge{{1,1}->{r}}++;}; ', 'olock' => '$fudge{1}++; ', 'odie' => '$judge{1}++; ', 'ofix' => '$budge{1}++; ', 'ofatal' => '$mudge{{1,1}->{1}}++; ', }); __END__
                Rate    fix  fatal   ofix   lock    die ofatal  olock   odie
    fix       5127/s     --   -96%   -96%   -97%   -98%   -99%  -100%  -100%
    fatal   114761/s  2138%     --    -5%   -31%   -46%   -76%   -97%   -97%
    ofix    120289/s  2246%     5%     --   -28%   -43%   -75%   -97%   -97%
    lock    167169/s  3161%    46%    39%     --   -21%   -65%   -96%   -96%
    die     212804/s  4051%    85%    77%    27%     --   -55%   -94%   -95%
    ofatal  477397/s  9211%   316%   297%   186%   124%     --   -88%   -90%
    olock  3861974/s 75226%  3265%  3111%  2210%  1715%   709%     --   -15%
    odie   4569982/s 89036%  3882%  3699%  2634%  2048%   857%    18%     --