Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Proxying (almost) all methods in a class for mass memoization

by hippo (Bishop)
on Aug 16, 2018 at 08:06 UTC ( [id://1220409]=note: print w/replies, xml ) Need Help??


in reply to Re: Proxying (almost) all methods in a class for mass memoization
in thread Proxying (almost) all methods in a class for mass memoization

And sub calls are slightly optimized if you leave [return] out.

That's a surprising twist. I would have imagined that such a thing would have been easily optimised away at compilation. I'm going to have to start benchmarking frequently-called, tiny subs to see what sort of difference this makes. Thanks (I think)!

Replies are listed 'Best First'.
Re^3: Proxying (almost) all methods in a class for mass memoization
by choroba (Cardinal) on Aug 16, 2018 at 10:01 UTC
    > I would have imagined that such a thing would have been easily optimised away at compilation

    And, unsurprisingly, it's been the case since 5.20!

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      I wonder what it takes to trigger that optimization.

      davido:~/scripts$ perlbrew exec --with perl-5.10.1 perl mytest.pl Perl version: 5.010001 Rate retn bare retn 6849315/s -- -8% bare 7462687/s 9% -- (25000000, 25000000) davido:~/scripts$ perlbrew exec --with perl-5.28.0 perl mytest.pl Perl version: 5.028000 Rate bare retn bare 10729614/s -- -3% retn 11013216/s 3% -- (25000000, 25000000)

      I mean I do see a difference, but other optimizations between Perl 5.10 and Perl 5.28 seem to be far more significant (probably the integer optimization).

      Here is the sample code:

      use strict; use warnings; use Benchmark qw(cmpthese); my $x; my $y; sub bare { ++$x; $x } sub retn { ++$y; return $y } print "Perl version: $]\n\n"; cmpthese(25_000_000, { bare => sub {my $t = bare()}, retn => sub {my $t = retn()}, }); print "\n($x, $y)\n";

      The reason for the double sub call is to assure that the return value is being obtained, and not discarded due to context. So we do have the double-call overhead, but it's the same overhead for both sides of the test.

      Anyway, where there had been a 9% difference in favor of bare returns in 5.10, there's now a statistically insignificant 3% difference that seems to go either direction.


      Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1220409]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-03-28 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found