This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
RT 75254: Slow GC after Scalar::Util::weaken
authorDavid Mitchell <davem@iabyn.com>
Sun, 31 Oct 2010 17:01:10 +0000 (17:01 +0000)
committerDavid Mitchell <davem@iabyn.com>
Mon, 1 Nov 2010 16:38:31 +0000 (16:38 +0000)
commit51698cb360d5bba06e12496ef9c7bf82e3352b71
tree98d362c2891820fa8fc1def26eaa824f33dd7ebd
parent328552296d8d53b34dfe2dcb81fd7119bdc526f5
RT 75254: Slow GC after Scalar::Util::weaken

Freeing lots of weak RVs to the same object results in quadratic
search through the backrefs array. This is probably sufficiently rare
that its not worth the expense of replacing the array with a ptr table
(say); but in the meantime, this patch makes the code as tight as
possible, and adds a check for the sv being at element 0, so that
both types of linear create/destroy order are optimised (previously only
created last / deleted first order was quick). It's still slow for random
deletion order. The RT code, modified to give high-res timing for the
return from the sub, and with various types of destruct order, gives the
following timings:

        LIFO   FIFO random
before 0.05s 17.37s 17.28s
now    0.04s  0.04s 12.05s
sv.c