Implement OwnedNode using a node decode plan.#34
Conversation
cheme
left a comment
There was a problem hiding this comment.
I like this node plan change, still it would make more sense if it would also use some OwnedNode<&'a[u8]> at some place in the code.
It seems the change in perf is a bit surprising, but my bench is done without much thinking, still got a 10 to 20 % reg on it (iteration on a inmemory trie).
https://gist.github.com/cheme/b5943e53ecce6aa54ded8eb0d128eef5
That is a bit problematic, but this is very naive bench, so having bench in the pr could help asserting the change impact at this point.
|
@cheme Thanks for pointing out the regression. I added a benchmark and some performance optimizations. I am now seeing at 18.8% perf improvement in this PR over master for trie iteration. |
| // unnecessarily. | ||
| IterStep::YieldNode | ||
| } else { | ||
| let node = b.node.node(); |
There was a problem hiding this comment.
naïve question, can't we just match on NodePlan instead, and only access the fields if they are needed.
There was a problem hiding this comment.
Nice, didn't think of that! With this, it's a 43% speedup over master!
1310c84 to
95075cc
Compare
The goal of this change is to remove some of the duplication and inefficiency of
OwnedNode.OwnedNodeis a parallel data structure toNodethat is constructed by copying a lot of data into new allocations. Notably, anOwnedNodecannot easily be converted to aNodebecause of alignment issues betweenNibbleVec, whichOwnedNodeuses to represent partial keys, andNibbleSlice, whichNodeuses to represent partial keys.The idea head is for
OwnedNodeto just store an encoded trie node along with a blueprint for quickly decoding into a node. When an encoded node is first decoded, instead of creating aNodedirectly, which has a lifetime, one can construct aNodePlanwhich is an owned structure and can be used to quickly create Nodes thereafter. TheOwnedNodecan be cheaply converted into aNodeby using theNodePlanon its owned data.This is a breaking change as it modifies the
NodeCodectrait and adds a new required method. This probably needs a minor version bump at a minimum. The actual code changes required to upgrade are fairly minimal though.Using the newly added benchmark, trie traversal on an in-memory trie is 42% faster.