Skip to content

Conversation

@therainisme
Copy link
Contributor

Rewrote compactToHex to allocate the exact buffer size upfront. This avoids the intermediate allocation and slicing overhead previously caused by keybytesToHex.

Also switched to bitwise operations for nibble handling in encoding.go and extracted the 100 threshold constant in trie.go.

Benchmarks:

goos: linux
goarch: amd64
pkg: github.com/ethereum/go-ethereum/trie
cpu: 12th Gen Intel(R) Core(TM) i5-12500

BenchmarkCompactToHex-12    	34527297	        36.71 ns/op	      16 B/op	       1 allocs/op  (baseline)
BenchmarkCompactToHex-12    	39204872	        31.94 ns/op	      16 B/op	       1 allocs/op  (optimized)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant