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

Revert "perf: move common_prefix_len out of loop" #5043

Merged
merged 1 commit into from
Oct 16, 2023
Merged

Conversation

rkrasiuk
Copy link
Member

Reverts #5036

common_prefix_len was inside the loop because it gets truncated at the end of the iteration. Rare case that was not hit in tests

current.truncate(preceding_len);
tracing::trace!(target: "trie::hash_builder", ?current, "truncated nibbles to {} bytes", preceding_len);

@rkrasiuk rkrasiuk added the A-trie Related to Merkle Patricia Trie implementation label Oct 16, 2023
@rkrasiuk rkrasiuk requested a review from gakonst as a code owner October 16, 2023 17:57
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Is there a way to test this?

@rkrasiuk rkrasiuk enabled auto-merge October 16, 2023 17:58
@codecov
Copy link

codecov bot commented Oct 16, 2023

Codecov Report

Merging #5043 (a1339db) into main (931065d) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

Files Coverage Δ
crates/primitives/src/trie/hash_builder/mod.rs 86.91% <100.00%> (ø)

... and 9 files with indirect coverage changes

Flag Coverage Δ
integration-tests 17.04% <100.00%> (-0.01%) ⬇️
unit-tests 62.26% <100.00%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 30.85% <ø> (ø)
blockchain tree 80.82% <ø> (ø)
pipeline 88.41% <ø> (ø)
storage (db) 74.43% <ø> (ø)
trie 94.51% <ø> (+0.03%) ⬆️
txpool 54.78% <ø> (-0.46%) ⬇️
networking 78.19% <ø> (ø)
rpc 58.43% <ø> (+<0.01%) ⬆️
consensus 63.01% <ø> (ø)
revm 28.20% <ø> (ø)
payload builder 7.96% <ø> (ø)
primitives 86.55% <100.00%> (+<0.01%) ⬆️

@rkrasiuk rkrasiuk added this pull request to the merge queue Oct 16, 2023
Merged via the queue into main with commit 0480f95 Oct 16, 2023
@rkrasiuk rkrasiuk deleted the revert-5036-prefix branch October 16, 2023 18:19
@robinsdan
Copy link
Contributor

Actually, I have noticed this truncate code, but it will not shrink to a length less than common_prefix_len within the loop as I commented in the original pr, because:

  1. to execute this line, it need first pass this if line :
  if preceding_len <= common_prefix_len && !succeeding.is_empty() {
                tracing::trace!(target: "trie::hash_builder", "no common prefix to create branch nodes from, returning");
                return // return here
 }

so preceding_len > common_prefix_len || succeeding.is_empty()

  1. if succeeding.is_empty() , then common_prefix_len == 0, and it will always be 0, move out of loop is safe.
  2. if preceding_len > common_prefix_len, then after truncation, current = current[.. preceding_len], common_prefix_len will still not change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trie Related to Merkle Patricia Trie implementation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants