Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Class::Std::Fast cache and threads

by Boldra (Deacon)
on Oct 12, 2010 at 11:09 UTC ( #864804=note: print w/ replies, xml ) Need Help??


in reply to Class::Std::Fast cache and threads

Currently I'm tending to this hack:

clean_cache: { no warnings qw<redefine once>; local *Class::Std::Fast::croak = sub {}; use warnings; delete Class::Std::Fast::_cache_class_ref()->{STR}; }
Recall that _cache_class_ref refuses to give me access to the list of cached classes if the caller is not a member of 'Class::Std', but this refusal is via croak, which I can redefine.


Comment on Re: Class::Std::Fast cache and threads
Download Code
Re^2: Class::Std::Fast cache and threads
by BrowserUk (Pope) on Oct 12, 2010 at 14:21 UTC

    Have you (or anyone) actually run any benchmarks to see how much time using this cache option actually saves?

    Because in my (admittedly simplistic) tests, it actually runs slower! Only by a microsecond or two, but still slower.

    And when I look inside and see that the only thing it caches is the scalar ref used as an id, that makes sense. That is, it makes sense that it is slower.

    It makes no sense (to me) to cache this at all. Indeed, if the caching was removed completely, it would run faster still because of the absence of the 'is-it-cached' tests.

    And without the caching, the OP problem just 'goes away'.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Definitely a good point. I haven't tested it myself, insteadI'm trusting the claims of the CSF author who says it's "an order of magnitude faster". You may have missed is that it's caching a blessed scalar ref, which means that on the next new call, it can just pop an item of the cache instead of blessing a new object. This is apparently where the speed saving comes from.

      I'm also a bit stuck with the problem that the caching is set at import in about 20 SOAP::WSDL::XSD::Typelib::Builtin::* modules (and possibly other modules autogenerated by wsdl2perl). I'm sticking with my "caching is faster" excuse for now though - I'll switch to "I'm too lazy" when I get desperate :)

        You may have missed is that it's caching a blessed scalar ref, which means that on the next new call, it can just pop an item of the cache instead of blessing a new object.

        Blessing a ref takes an infinitesimal amount of time. My benchmark:

        package STR; use Class::Std::Fast; ## cache => 1; package main; use Time::HiRes qw[ time ]; my $start = time; STR->new for 1 .. 1e6; printf "Took %.8f seconds\n", ( time - $start ) / 1e6; __END__ ## With caching c:\test>junk64 Took 0.00002447 seconds ## Without caching c:\test>junk64 Took 0.00002391 seconds

        And if you removed all the cache related conditionals, it would be quicker still.

        It would also avoid your original problem


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2014-10-21 04:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (96 votes), past polls