• Felix Lange's avatar
    core/types: faster RLP encoding of Header, StateAcccount, ReceiptForStorage (#24420) · d6f49bf7
    Felix Lange authored
    This change makes use of the new code generator rlp/rlpgen to improve the
    performance of RLP encoding for Header and StateAccount. It also speeds up
    encoding of ReceiptForStorage using the new rlp.EncoderBuffer API.
    
    The change is much less transparent than I wanted it to be, because Header and
    StateAccount now have an EncodeRLP method defined with pointer receiver. It
    used to be possible to encode non-pointer values of these types, but the new
    method prevents that and attempting to encode unadressable values (even if
    part of another value) will return an error. The error can be surprising and may
    pop up in places that previously didn't expect any errors.
    
    To make things work, I also needed to update all code paths (mostly in unit tests)
    that lead to encoding of non-pointer values, and pass a pointer instead.
    
    Benchmark results:
    
        name                             old time/op    new time/op    delta
        EncodeRLP/legacy-header-8           328ns ± 0%     237ns ± 1%   -27.63%  (p=0.000 n=8+8)
        EncodeRLP/london-header-8           353ns ± 0%     247ns ± 1%   -30.06%  (p=0.000 n=8+8)
        EncodeRLP/receipt-for-storage-8     237ns ± 0%     123ns ± 0%   -47.86%  (p=0.000 n=8+7)
        EncodeRLP/receipt-full-8            297ns ± 0%     301ns ± 1%    +1.39%  (p=0.000 n=8+8)
    
        name                             old speed      new speed      delta
        EncodeRLP/legacy-header-8        1.66GB/s ± 0%  2.29GB/s ± 1%   +38.19%  (p=0.000 n=8+8)
        EncodeRLP/london-header-8        1.55GB/s ± 0%  2.22GB/s ± 1%   +42.99%  (p=0.000 n=8+8)
        EncodeRLP/receipt-for-storage-8  38.0MB/s ± 0%  64.8MB/s ± 0%   +70.48%  (p=0.000 n=8+7)
        EncodeRLP/receipt-full-8          910MB/s ± 0%   897MB/s ± 1%    -1.37%  (p=0.000 n=8+8)
    
        name                             old alloc/op   new alloc/op   delta
        EncodeRLP/legacy-header-8           0.00B          0.00B           ~     (all equal)
        EncodeRLP/london-header-8           0.00B          0.00B           ~     (all equal)
        EncodeRLP/receipt-for-storage-8     64.0B ± 0%      0.0B       -100.00%  (p=0.000 n=8+8)
        EncodeRLP/receipt-full-8             320B ± 0%      320B ± 0%      ~     (all equal)
    d6f49bf7
Name
Last commit
Last update
.github Loading commit data...
accounts Loading commit data...
build Loading commit data...
cmd Loading commit data...
common Loading commit data...
consensus Loading commit data...
console Loading commit data...
contracts/checkpointoracle Loading commit data...
core Loading commit data...
crypto Loading commit data...
docs Loading commit data...
eth Loading commit data...
ethclient Loading commit data...
ethdb Loading commit data...
ethstats Loading commit data...
event Loading commit data...
graphql Loading commit data...
internal Loading commit data...
les Loading commit data...
light Loading commit data...
log Loading commit data...
metrics Loading commit data...
miner Loading commit data...
mobile Loading commit data...
node Loading commit data...
p2p Loading commit data...
params Loading commit data...
rlp Loading commit data...
rpc Loading commit data...
signer Loading commit data...
swarm Loading commit data...
tests Loading commit data...
trie Loading commit data...
.dockerignore Loading commit data...
.gitattributes Loading commit data...
.gitignore Loading commit data...
.gitmodules Loading commit data...
.golangci.yml Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
AUTHORS Loading commit data...
COPYING Loading commit data...
COPYING.LESSER Loading commit data...
Dockerfile Loading commit data...
Dockerfile.alltools Loading commit data...
Makefile Loading commit data...
README.md Loading commit data...
SECURITY.md Loading commit data...
appveyor.yml Loading commit data...
circle.yml Loading commit data...
go.mod Loading commit data...
go.sum Loading commit data...
interfaces.go Loading commit data...
oss-fuzz.sh Loading commit data...