• Hiroshi Ioka's avatar
    encoding/asn1: reduce allocations in Marshal · ae4aac00
    Hiroshi Ioka authored
    Current code uses trees of bytes.Buffer as data representation.
    Each bytes.Buffer takes 4k bytes at least, so it's waste of memory.
    The change introduces trees of lazy-encoder as
    alternative one which reduce allocations.
    
    name       old time/op    new time/op    delta
    Marshal-4    64.7µs ± 2%    42.0µs ± 1%  -35.07%   (p=0.000 n=9+10)
    
    name       old alloc/op   new alloc/op   delta
    Marshal-4    35.1kB ± 0%     7.6kB ± 0%  -78.27%  (p=0.000 n=10+10)
    
    name       old allocs/op  new allocs/op  delta
    Marshal-4       503 ± 0%       293 ± 0%  -41.75%  (p=0.000 n=10+10)
    
    Change-Id: I32b96c20b8df00414b282d69743d71a598a11336
    Reviewed-on: https://go-review.googlesource.com/27030Reviewed-by: 's avatarAdam Langley <agl@golang.org>
    Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
    Run-TryBot: Adam Langley <agl@golang.org>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    ae4aac00
asn1_test.go 37.8 KB