Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: threads::shared seems to kill performance

by dave_the_m (Monsignor)
on Jul 17, 2013 at 22:42 UTC ( [id://1044918]=note: print w/replies, xml ) Need Help??


in reply to threads::shared seems to kill performance

threads::shared variables are *very* slow; you should share little, and access it not a lot.

The implementation essentially does a similar thing to tieing (except that it's implemented in XS rather than perl); so

my %hash : shared; ... $x = $hash{foo};
is a bit like
sub threads::shared::FETCH { lock $Some:Global:lock_var; return $Some::Shared::Space::hash{$_[0]}; } my %hash; tie %hash, 'threads::shared'; ...
Note that each thread has its own copy of the 'tied' hash; accessing it causes a global lock to be set, then an entry from the 'real' hash is copied to that thread.

Dave.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-25 17:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found