Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trie: preallocate capacity for fields slice #29614

Merged
merged 1 commit into from
Apr 24, 2024

Conversation

qcrao
Copy link
Contributor

@qcrao qcrao commented Apr 23, 2024

This avoids multiple memory allocations and array resizing when appending elements, making the code more efficient.

@@ -78,7 +78,7 @@ func NewNodeSet(owner common.Hash) *NodeSet {
// ForEachWithOrder iterates the nodes with the order from bottom to top,
// right to left, nodes with the longest path will be iterated first.
func (set *NodeSet) ForEachWithOrder(callback func(path string, n *Node)) {
var paths []string
paths := make([]string, 0, len(set.Nodes))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be useful. As normally we have thousands of dirty nodes in each block, could be beneficial in hash-based scheme.

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@holiman holiman added this to the 1.14.1 milestone Apr 23, 2024
@holiman holiman changed the title trie: Preallocate capacity for fields slice trie: preallocate capacity for fields slice Apr 24, 2024
@holiman holiman merged commit ac21f9b into ethereum:master Apr 24, 2024
3 checks passed
jorgemmsilva pushed a commit to iotaledger/go-ethereum that referenced this pull request Jun 17, 2024
trie: Preallocate capacity for fields slice
stwiname pushed a commit to subquery/data-node-go-ethereum that referenced this pull request Sep 9, 2024
trie: Preallocate capacity for fields slice
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.

3 participants