develooper Front page | perl.perl5.porters | Postings from February 2006

[PATCH] Speedups and shrinkages of SvREFCNT_inc

Thread Next
February 24, 2006 12:54
[PATCH] Speedups and shrinkages of SvREFCNT_inc
Message ID:
Here's a patch that I think should speed up things about 1-2%, since it
improves a lot of code where we do reference counting.

While looking at compiler errors from GCC, I found a lot of places where
we were passing NULL to parms that couldn't have NULL.  Turns out that
we weren't explicitly passing NULL, but it was a possibility, as in:

    if (sv) {
        some_func( SvREFCNT_inc(sv) );

The way SvREFCNT_inc is written, it's basically:

    (sv) ? (SvREFCNT(sv)++,sv) : NULL

so that the compiler says "oh, it's possible for you to pass a NULL to

So I made a version of SvREFCNT_inc that says "You promise not to send
in a NULL, and I promise not to return one".

and then I made one that was a void context so you wouldn't have to
(void) everywhere, and the macro wouldn't have code to return a value
that would get optimized away

and then I made one that doesn't save a copy of the argument to get
around argument side effects.  SvREFCNT_inc handles the case of
SvREFCNT_inc( *foo++ ), but at the expense of extra code in the case of
SvREFCNT_inc( sv );

And then I made combinations of all of the above.  And all of them work
exactly as in SvREFCNT_inc(), assuming you call them at appropriate

And here's the patch.  It would be swell if someone with better
measurement-fu than I would time before & after.  My make test timings
are all over the board, but I would expect a bigger speedup since
reference counting is pretty common.

u=5.05  s=1.13  cu=272.58  cs=25.72  scripts=1157  tests=161482

u=4.88  s=1.01  cu=277.26  cs=26.20  scripts=1157  tests=161482
u=4.69  s=1.00  cu=269.83  cs=26.40  scripts=1157  tests=161482
u=4.91  s=1.07  cu=262.68  cs=26.49  scripts=1157  tests=161482

I DO know that the binary is about 600 bytes smaller.


Andy Lester => => => AIM:petdance

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About