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

Add NodeHandle enum for node references within Node #35

Merged
merged 3 commits into from
Nov 19, 2019

Conversation

jimpo
Copy link
Contributor

@jimpo jimpo commented Nov 11, 2019

Currently, branch and extension nodes just have a byte slice reference to the child nodes and one uses the NodeCodec::try_decode_hash method to determine whether it is a hash or an inline node reference. Instead, we make this an explicit part of the decoded Node structure to simply code and make the codec more flexible. For example, we can stop encoding the length of the hashes inside branch nodes and instead use another bitfield inside branch nodes to indicate whether each child is a hash or inline reference, which should save space.

This is another breaking change to NodeCodec building on #34.

@jimpo jimpo requested review from cheme and arkpar November 11, 2019 18:25
Copy link
Contributor

@cheme cheme left a comment

Choose a reason for hiding this comment

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

Running same bench as in #34, the perf from #34 degrades (8%), I am not sure about the origin of it but it could have been related to the fact that children have to decode their inline nodes but the bench is on iterator so it should go into all inline node, so it is probably not that (unless there is multiple calls to that).

Regarding the PR, I agree that this try_decode_hash should not be a codec method. Maybe there is a way to put it in another trait like Layout or somewhere else, to avoid those static rules (size == lenght(hash)) in code.

@@ -100,72 +100,84 @@ where
{
// load an inline node into memory or get the hash to do the lookup later.
fn inline_or_hash<C, H>(
node: &[u8],
parent_hash: H::Out,
Copy link
Contributor

Choose a reason for hiding this comment

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

'parent_hash' as a pointer here?

NodeHandle::Hash(hash)
},
EncodedNodeHandle::Inline(data) => {
let child = Node::from_encoded::<C, H>(parent_hash, data, db, storage)?;
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible that the small perf hit comes from getting a decoded data handle when previously it was encoded data? I don't really think so (exept if from branch this method is called on child we do not need, but it should not), but I am not sure where it comes from.

child(4), child(5), child(6), child(7),
child(8), child(9), child(10), child(11),
child(12), child(13), child(14), child(15),
child(0)?, child(1)?, child(2)?, child(3)?,
Copy link
Contributor

Choose a reason for hiding this comment

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

ok we are doing it here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the performance hit may come for the fact that before this pr, call to child here only went into try_decode_hash that do not do inline node decoding.
After this pr for all inline node (even if not needed) we run a decoding step.

Copy link
Contributor

Choose a reason for hiding this comment

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

But it shouldn't matter for iteration since all child are queried, for other operation it can, but it is probably minor.

@cheme
Copy link
Contributor

cheme commented Nov 12, 2019

No sorry, I misread the code, there is no such static rules.

@arkpar
Copy link
Member

arkpar commented Nov 18, 2019

Needs a rebase

@jimpo jimpo force-pushed the jimpo/decode-hash branch from 41a51f8 to 42574e6 Compare November 18, 2019 16:07
@arkpar
Copy link
Member

arkpar commented Nov 19, 2019

Performance hit might come from from_encoded returning Result now. I think proper error handling is still worth it though.

@arkpar arkpar merged commit c5c64a4 into master Nov 19, 2019
@arkpar arkpar deleted the jimpo/decode-hash branch November 19, 2019 11:56
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