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

[PATCH] Speedups and shrinkages of SvREFCNT_inc

Thread Next
From:
andy
Date:
February 24, 2006 12:54
Subject:
[PATCH] Speedups and shrinkages of SvREFCNT_inc
Message ID:
20060224205434.GA17867@petdance.com
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
me!"  

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
times.

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.

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

NEW
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.

xoxo,
Andy



-- 
Andy Lester => andy@petdance.com => www.petdance.com => AIM:petdance

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