Hello wise monks, I'm trying to increase performance of my program (which uses a huge 3-dimensional hash - around 240MB in RAM) by moving it to a threaded model.
I though I'd explicitly share the big hash and then access the data from each thread (the operations I do are read only, so I'm not worried about individual threads conflicting).
However the process of creating the big shared hash takes ages for some reason - I've tried these two simplified versions for comparison:
vs the shared one:my %data; foreach my $x (1..5000) { $data{$x} = {} unless $data{$x}; foreach my $y (1..1000) { $data{$x}{$y} = {} unless $data{$x}{$y}; } } real 0m4.075s user 0m3.767s sys 0m0.289s
use threads; use threads::shared; my %data:shared; foreach my $x (1..5000) { $data{$x} = &share( {} ) unless $data{$x}; foreach my $y (1..1000) { $data{$x}{$y} = &share( {} ) unless $data{$x}{$y}; } } real 1m4.984s user 1m4.211s ! that's ~16x times slower that the non-shared case sys 0m0.540s
Is there something wrong with my code or is this performance decrease simply an inevitable cost of sharing?
In reply to threads::shared seems to kill performance by Jacobs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |