]> Cypherpunks repositories - gostls13.git/commit
big: reduce the number of allocations
authorEvan Shaw <chickencha@gmail.com>
Wed, 21 Apr 2010 04:24:07 +0000 (21:24 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 21 Apr 2010 04:24:07 +0000 (21:24 -0700)
commit4f445d2744337bd0565c8e8eb1523f512a180d4e
tree89952b5e16dc073fdf99bce20bba36703f149e24
parent0857573a673c122f7a27311423da3ca2fab739d3
big: reduce the number of allocations

There was a bug in makeN that caused lots of unnecessary
allocations.  Fixing this exposed a few bugs in other
functions which worked when makeN allocated a new slice, but
failed when it simply resized an existing slice.  The result
is a pretty big performance improvement.  When running
pidigits, here were the numbers I got on amd64:

Before this change:
pidigits 10000
        gcc -O2 pidigits.c -lgmp        2.09u 0.02s 2.11r
        gc pidigits     12.68u 0.04s 12.72r
        gc_B pidigits   12.71u 0.03s 12.75r

After:
pidigits 10000
        gcc -O2 pidigits.c -lgmp        2.09u 0.00s 2.10r
        gc pidigits     6.82u 0.00s 6.85r
        gc_B pidigits   6.55u 0.01s 6.59r

R=rsc, gri
CC=golang-dev
https://golang.org/cl/953042
src/pkg/big/nat.go