rlp: reduce allocations for big.Int and byte array encoding (#21291)

This change further improves the performance of RLP encoding by removing
allocations for big.Int and [...]byte types. I have added a new benchmark
that measures RLP encoding of types.Block to verify that performance is
improved.
This commit is contained in:
Felix Lange
2020-07-06 11:17:09 +02:00
committed by GitHub
parent fa01117498
commit 6315b6fcc0
4 changed files with 222 additions and 43 deletions

View File

@ -210,6 +210,10 @@ func isUint(k reflect.Kind) bool {
return k >= reflect.Uint && k <= reflect.Uintptr
}
func isByte(typ reflect.Type) bool {
return typ.Kind() == reflect.Uint8 && !typ.Implements(encoderInterface)
}
func isByteArray(typ reflect.Type) bool {
return (typ.Kind() == reflect.Slice || typ.Kind() == reflect.Array) && isByte(typ.Elem())
}