-
Notifications
You must be signed in to change notification settings - Fork 113
Open
Description
The go-ethereum/accounts/abi library use runtime reflection for convenience, but it's inefficient and introduce many runtime error and panic conditions (see #269 for example).
go-abi is developed just for precompile usage, it use code generation and generate statically typed structs and encoding/decoding routines. It's both safer to use and magnitudes faster than go-ethereum.
BTW, solidity's abi.encode/abi.decode functions are not implemented with go-ethereum/accounts/abi, they are also special treated by solc to generate code at compile time.
Benchmark
Benchmark shows that go-abi is magnitudes faster, and do exactly 1 allocation per operation.
$ go test -bench=. -benchmem -benchtime=5s ./tests/...
eth length 1028
goos: darwin
goarch: arm64
pkg: github.com/yihuang/go-abi/tests
cpu: Apple M3 Max
BenchmarkGoABI_ComplexDynamicTuples-16 14653149 431.2 ns/op 3072 B/op 1 allocs/op
BenchmarkGoABI_NestedDynamicArrays-16 20507278 285.6 ns/op 1280 B/op 1 allocs/op
BenchmarkGoABI_MixedTypes-16 44948070 134.7 ns/op 896 B/op 1 allocs/op
BenchmarkGoEthereum_ComplexDynamicTuples-16 424966 13945 ns/op 49385 B/op 372 allocs/op
BenchmarkGoEthereum_NestedDynamicArrays-16 1388450 4330 ns/op 13504 B/op 151 allocs/op
BenchmarkGoEthereum_MixedTypes-16 1391089 4302 ns/op 9296 B/op 116 allocs/op
BenchmarkGoABI_EncodeOnly_ComplexDynamicTuples-16 13514184 442.9 ns/op 3072 B/op 1 allocs/op
BenchmarkGoABI_EncodeTo_ComplexDynamicTuples-16 41147829 147.8 ns/op 0 B/op 0 allocs/op
BenchmarkGoABI_MemoryAllocations_ComplexDynamicTuples-16 13679475 442.8 ns/op 3072 B/op 1 allocs/op
BenchmarkGoEthereum_MemoryAllocations_ComplexDynamicTuples-16 379189 14353 ns/op 49385 B/op 372 allocs/op
PASS
ok github.com/yihuang/go-abi/tests 71.209s
cloudgray
Metadata
Metadata
Assignees
Labels
No labels