develooper Front page | perl.perl5.porters | Postings from September 2003

[PATCH] threads/shared.pm: saves 4K per thread

Thread Next
From:
Elizabeth Mattijsen
Date:
September 5, 2003 05:46
Subject:
[PATCH] threads/shared.pm: saves 4K per thread
Message ID:
p05111b05bb7e177db044@[192.168.56.4]
Included is a patch to threads/shared.pm that saves about 4K of
memory per started thread.  This is achieved by removing the
"disabled" versions of several subroutines to a string eval that is
only executed when threads were not loaded.  All tests pass with this
patch.  I also upped the Perl version check to 5.8 (was 5.7.3).

These are the results from Benchmark::Thread::Size: the first is the
original shared.pm, the second is the adapted shared.pm.  When using
hunderd threads, this saves about 330K of memory, slightly more than
1% lower memory usage.

====================================================
use Benchmark::Thread::Size times => 5, shared => <<'E1';
use threads::shared;
E1
====================================================

   #   (ref)      shared.original
   0    1723 ± 4     +96
   1    2092 ± 6    +148 ± 4
   2    2390 ± 4    +173
   5    3280 ± 2    +254 ± 6
  10    4767 ± 4    +394 ± 4
  20    7743 ± 6    +678 ±32
  50   16670 ±14   +1476 ±16
100   31559 ± 6   +2826 ±24

   #   (ref)      shared.new
   0    1723 ± 4     +88
   1    2088 ± 2    +140 ± 2
   2    2388 ± 2    +159
   5    3280 ± 2    +232 ± 2
  10    4768 ± 4    +347 ± 4
  20    7738 ±12    +590 ± 4
  50   16672 ±12   +1294 ±14
100   31528 ±16   +2495 ±24

254 - 232 = 22 / 5 = 4.40K per thread using 5 threads
2826 - 2495 = 331 / 100 = 3.31 K per thread using 100 threads


The savings in CPU are minimal but definitely above background noise.

======================================================
use threads;
use threads::shared;
use Benchmark;
timethis (200, sub { threads->new( sub { 1 } )->join } );
======================================================

shared.original:
timethis 200: 10 wallclock secs ( 9.27 usr +  0.00 sys =  9.27 CPU) @
21.57/s (n=200)

shared.new
timethis 200: 10 wallclock secs ( 9.13 usr +  0.00 sys =  9.13 CPU) @
21.91/s (n=200)



Liz
Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About