Skip to content

Refactor/cliff/dev op#39

Open
cliff0412 wants to merge 15 commits intodev-opfrom
refactor/cliff/dev-op
Open

Refactor/cliff/dev op#39
cliff0412 wants to merge 15 commits intodev-opfrom
refactor/cliff/dev-op

Conversation

@cliff0412
Copy link
Copy Markdown

@cliff0412 cliff0412 commented Sep 18, 2025

use stackTrie when committing genesis storage trie nodes

stackTrie only traverse mpt once while trie performs one traverse to hash first and then perform one commit; therefore, trie allocs more memory in saving the direty nodes. below is the bench result

stackTrie

// BenchmarkStackTrieInsertion/Size_1000
// BenchmarkStackTrieInsertion/Size_1000-12 739 1617923 ns/op 582738 B/op 9122 allocs/op
// BenchmarkStackTrieInsertion/Size_10000
// BenchmarkStackTrieInsertion/Size_10000-12 70 16953160 ns/op 5805821 B/op 92059 allocs/op
// BenchmarkStackTrieInsertion/Size_100000
// BenchmarkStackTrieInsertion/Size_100000-12 6 177203236 ns/op 61306298 B/op 917144 allocs/op
// BenchmarkStackTrieInsertion/Size_1000000
// BenchmarkStackTrieInsertion/Size_1000000-12 1 1964037625 ns/op 582744808 B/op 9085699 allocs/op

regular trie

// BenchmarkRegularTrieInsertion/Size_1000
// BenchmarkRegularTrieInsertion/Size_1000-12 482 2429196 ns/op 2080139 B/op 27682 allocs/op
// BenchmarkRegularTrieInsertion/Size_10000
// BenchmarkRegularTrieInsertion/Size_10000-12 70 16680217 ns/op 20157853 B/op 275211 allocs/op
// BenchmarkRegularTrieInsertion/Size_100000
// BenchmarkRegularTrieInsertion/Size_100000-12 6 180554403 ns/op 207196216 B/op 2741910 allocs/op
// BenchmarkRegularTrieInsertion/Size_1000000
// BenchmarkRegularTrieInsertion/Size_1000000-12 1 2423703250 ns/op 2099059016 B/op 27041567 allocs/op

alloc: stackTrie allocs 582744808 bytes per op, while regular trie alloc 2099059016 bytes per op, which is 3.6x less
speed: stackTrie takes 1964037625 ns per op, while regular trie takes 2423703250 ns, which is 23% faster

@cliff0412 cliff0412 closed this Sep 18, 2025
@cliff0412 cliff0412 reopened this Sep 19, 2025
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