perl5 icon indicating copy to clipboard operation
perl5 copied to clipboard

Refactor Perl_av_fetch, optimize path for non-negative key access

Open bbrtj opened this issue 3 days ago • 3 comments

This change refactors Perl_av_fetch function and moves the re-calculation of key, so that it happens only if the key is not found in range between 0 and max_index. Fetching existing non-negative elements should be much more common than the alternatives, and this change should reduce the number of instructions needed to achieve that.

I've run Porting/bench.pl script against all tests that start with expr::array, here are the average results:

       hacked  blead
       ------ ------
    Ir 100.00  97.63
    Dr 100.00 100.00
    Dw 100.00  97.14
  COND 100.00 101.30
   IND 100.00 100.00

COND_m 100.00 100.00
 IND_m 100.00  98.36

 Ir_m1 100.00 102.22
 Dr_m1 100.00 100.00
 Dw_m1 100.00 100.00

 Ir_mm 100.00 100.00
 Dr_mm 100.00 100.00
 Dw_mm 100.00 100.00

Tests which contributed to COND being higher were expr::array::pkg_1const_m1 and expr::array::lex_1const_m1 - not unexpected. Single L1 cache miss comes from expr::arrayhash::lex_3var test, and surprisingly, the pkg version of the same test did not miss the cache.


  • This set of changes does not require a perldelta entry.

bbrtj avatar Dec 09 '25 16:12 bbrtj