plugeth/rlp
Felix Lange 32c576bd3c
rlp: minor optimizations for slice/array encoding (#23467)
As per benchmark results below, these changes speed up encoding/decoding of
consensus objects a bit.

    name                             old time/op    new time/op    delta
    EncodeRLP/legacy-header-8           384ns ± 1%     331ns ± 3%  -13.83%  (p=0.000 n=7+8)
    EncodeRLP/london-header-8           411ns ± 1%     359ns ± 2%  -12.53%  (p=0.000 n=8+8)
    EncodeRLP/receipt-for-storage-8     251ns ± 0%     239ns ± 0%   -4.97%  (p=0.000 n=8+8)
    EncodeRLP/receipt-full-8            319ns ± 0%     300ns ± 0%   -5.89%  (p=0.000 n=8+7)
    EncodeRLP/legacy-transaction-8      389ns ± 1%     387ns ± 1%     ~     (p=0.099 n=8+8)
    EncodeRLP/access-transaction-8      607ns ± 0%     581ns ± 0%   -4.26%  (p=0.000 n=8+8)
    EncodeRLP/1559-transaction-8        627ns ± 0%     606ns ± 1%   -3.44%  (p=0.000 n=8+8)
    DecodeRLP/legacy-header-8           831ns ± 1%     813ns ± 1%   -2.20%  (p=0.000 n=8+8)
    DecodeRLP/london-header-8           824ns ± 0%     804ns ± 1%   -2.44%  (p=0.000 n=8+7)

* rlp: pass length to byteArrayBytes

This makes it possible to inline byteArrayBytes. For arrays, the length is known
at encoder construction time, so the call to v.Len() can be avoided.

* rlp: avoid IsNil for pointer encoding

It's actually cheaper to use Elem first, because it performs less checks
on the value. If the pointer was nil, the result of Elem is 'invalid'.

* rlp: minor optimizations for slice/array encoding

For empty slices/arrays, we can avoid storing a list header entry in the
encoder buffer. Also avoid doing the tail check at encoding time because
it is already known at encoder construction time.
2021-08-25 19:01:10 +02:00
..
decode_tail_test.go all: update license information 2016-04-15 09:48:05 +02:00
decode_test.go rlp: optimize big.Int decoding for size <= 32 bytes (#22927) 2021-05-25 21:56:25 +02:00
decode.go rlp: minor optimizations for slice/array encoding (#23467) 2021-08-25 19:01:10 +02:00
doc.go rlp: add support for optional struct fields (#22832) 2021-05-07 14:37:13 +02:00
encode_test.go rlp: minor optimizations for slice/array encoding (#23467) 2021-08-25 19:01:10 +02:00
encode.go rlp: minor optimizations for slice/array encoding (#23467) 2021-08-25 19:01:10 +02:00
encoder_example_test.go rlp: improve nil pointer handling (#20064) 2019-09-13 11:10:57 +02:00
iterator_test.go cmd, core, eth: background transaction indexing (#20302) 2020-05-11 18:58:43 +03:00
iterator.go core/rawdb: fix transaction indexing/unindexing hashing error (#22457) 2021-03-16 12:15:14 +02:00
raw_test.go p2p/rlpx: reduce allocation and syscalls (#22899) 2021-05-27 10:19:13 +02:00
raw.go p2p/rlpx: reduce allocation and syscalls (#22899) 2021-05-27 10:19:13 +02:00
safe.go rlp: minor optimizations for slice/array encoding (#23467) 2021-08-25 19:01:10 +02:00
typecache.go rlp: use atomic.Value for type cache (#22902) 2021-05-22 13:34:29 +02:00
unsafe.go rlp: minor optimizations for slice/array encoding (#23467) 2021-08-25 19:01:10 +02:00