Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Re: May Thy Closures Be Blessed

by eserte (Deacon)
on Apr 26, 2004 at 17:43 UTC ( #348270=note: print w/replies, xml ) Need Help??


in reply to Re: May Thy Closures Be Blessed
in thread May Thy Closures Be Blessed

This is probably due to inefficient stringification of the object reference. Maybe the stringified value should be put into the PV portion and POK should be set on while doing Perl_sv_2pv_flags ?

Replies are listed 'Best First'.
Re^3: May Thy Closures Be Blessed
by adrianh (Chancellor) on Apr 26, 2004 at 21:23 UTC
    This is probably due to inefficient stringification of the object reference. Maybe the stringified value should be put into the PV portion and POK should be set on while doing Perl_sv_2pv_flags ?

    I think this evaluation is spot on. If you change the inside-out implementation to something that avoids stringification:

    You get something much more reasonable:

    Rate closure inside_out traditional closure 177/s -- -43% -45% inside_out 313/s 76% -- -3% traditional 321/s 81% 3% --
      Very nice. Big savings because of caching the calculation of stringified value (I get an 18% difference, not a 3%). Unfortunally, this technique can't be used if you are subclassing a class that doesn't coorperate - then you will to call refaddr in each method. That's slower (traditional method being 69% faster), but faster than what I showed before. I would have expected to be able to gain a little more by writing the methods like:
      sub name { my $key = ${+shift}; $name {$key} = shift if @_; $name {$key}; }
      but that doesn't give me any gain (or loss).

      Abigail

        I get an 18% difference, not a 3%

        Hmm. I do seem to have been lucky with my initial runs. I'm seeing between 3-10% on my box, but nothing near 18%. How odd.

        Unfortunally, this technique can't be used if you are subclassing a class that doesn't coorperate

        True. Although for hash based objects you could just use one slot for the key and still get safety for all your other state hashes.

        I would have expected to be able to gain a little more by writing the methods like ...

        Good point. Can any internals expert explain why +shift is so slow?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://348270]
help
Chatterbox?
[Corion]: Oh yay. Thanks to The New Firefox, my irc client ChatZilla doesn't work anymore either... So I'll have to keep an old FF around just for that...
[Corion]: 100% of my FF add-ons are unsupported currently. Maybe upgrading Firefox wasn't such a good idea after all ;)
[Corion]: Also suffering is my 2-factor Github sign-in, as now, FF can't read my USB token anymore. "This was a horrible idea" is slowly dawning on me ;)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2017-11-20 20:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (293 votes). Check out past polls.

    Notices?