-
Notifications
You must be signed in to change notification settings - Fork 627
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
store: make RawTrieNode borsh serialisable #8744
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Replace Children::encode_into and decode methods by implementations of BorshSerializable and BorshDeserializable traits and with that change RawTrieNode into an enum for which borsh implementations can be derived. While the first step is quite straightforward, the second requires RawTrieNode::Branch variant being split into two: BranchNoValue and BranchWithValue. The main benefit of this is less code (the commit has delta of -68 lines) and API consistent with other serialised objects. However, this doesn’t come without downsides. Firstly, having separate BranchNoValue and BranchWithValue branches means that it’s now a bit more awkward to handle branch as a single case with common code paths having to be refactored. Secondly, one might imagine in the future a new representation for nodes which embed value. For example <4u8><key_len:u32><key><value> might be added for a leaf. This would essentially mean that value comprises of the rest of encoded bytes. The issue for borsh is that it would like to know length of <value> before it reads it. Either redundant <value_len:u32> would need to be included or some hacks employed (namely not using borsh for RawTrieNodeWithSize and then consuming the rest of the reader when decoding RawTrieNode). Lastly, I’m not certain about performance implications. Borsh might actually be slower than hand-implemented decoder which operates on a slice. If this is actually the case I haven’t measured.
robin-near
approved these changes
Mar 22, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks much cleaner, thanks!
Can I haz S-automerge? |
Friendly ping. |
nikurt
pushed a commit
that referenced
this pull request
Apr 18, 2023
Replace Children::encode_into and decode methods by implementations of BorshSerializable and BorshDeserializable traits and with that change RawTrieNode into an enum for which borsh implementations can be derived. While the first step is quite straightforward, the second requires RawTrieNode::Branch variant being split into two: BranchNoValue and BranchWithValue. The main benefit of this is less code (the commit has delta of -68 lines) and API consistent with other serialised objects. However, this doesn’t come without downsides. Firstly, having separate BranchNoValue and BranchWithValue branches means that it’s now a bit more awkward to handle branch as a single case with common code paths having to be refactored. Secondly, one might imagine in the future a new representation for nodes which embed value. For example {4u8}{key_len:u32}{key}{value} might be added for a leaf. This would essentially mean that value comprises of the rest of encoded bytes. The issue for borsh is that it would like to know length of {value} before it reads it. Either redundant {value_len:u32} would need to be included or some hacks employed (namely not using borsh for RawTrieNodeWithSize and then consuming the rest of the reader when decoding RawTrieNode). Lastly, I’m not certain about performance implications. Borsh might actually be slower than hand-implemented decoder which operates on a slice. If this is actually the case I haven’t measured.
nikurt
pushed a commit
that referenced
this pull request
Apr 25, 2023
Replace Children::encode_into and decode methods by implementations of BorshSerializable and BorshDeserializable traits and with that change RawTrieNode into an enum for which borsh implementations can be derived. While the first step is quite straightforward, the second requires RawTrieNode::Branch variant being split into two: BranchNoValue and BranchWithValue. The main benefit of this is less code (the commit has delta of -68 lines) and API consistent with other serialised objects. However, this doesn’t come without downsides. Firstly, having separate BranchNoValue and BranchWithValue branches means that it’s now a bit more awkward to handle branch as a single case with common code paths having to be refactored. Secondly, one might imagine in the future a new representation for nodes which embed value. For example {4u8}{key_len:u32}{key}{value} might be added for a leaf. This would essentially mean that value comprises of the rest of encoded bytes. The issue for borsh is that it would like to know length of {value} before it reads it. Either redundant {value_len:u32} would need to be included or some hacks employed (namely not using borsh for RawTrieNodeWithSize and then consuming the rest of the reader when decoding RawTrieNode). Lastly, I’m not certain about performance implications. Borsh might actually be slower than hand-implemented decoder which operates on a slice. If this is actually the case I haven’t measured.
nikurt
pushed a commit
that referenced
this pull request
Apr 25, 2023
Replace Children::encode_into and decode methods by implementations of BorshSerializable and BorshDeserializable traits and with that change RawTrieNode into an enum for which borsh implementations can be derived. While the first step is quite straightforward, the second requires RawTrieNode::Branch variant being split into two: BranchNoValue and BranchWithValue. The main benefit of this is less code (the commit has delta of -68 lines) and API consistent with other serialised objects. However, this doesn’t come without downsides. Firstly, having separate BranchNoValue and BranchWithValue branches means that it’s now a bit more awkward to handle branch as a single case with common code paths having to be refactored. Secondly, one might imagine in the future a new representation for nodes which embed value. For example {4u8}{key_len:u32}{key}{value} might be added for a leaf. This would essentially mean that value comprises of the rest of encoded bytes. The issue for borsh is that it would like to know length of {value} before it reads it. Either redundant {value_len:u32} would need to be included or some hacks employed (namely not using borsh for RawTrieNodeWithSize and then consuming the rest of the reader when decoding RawTrieNode). Lastly, I’m not certain about performance implications. Borsh might actually be slower than hand-implemented decoder which operates on a slice. If this is actually the case I haven’t measured.
nikurt
pushed a commit
that referenced
this pull request
Apr 25, 2023
Replace Children::encode_into and decode methods by implementations of BorshSerializable and BorshDeserializable traits and with that change RawTrieNode into an enum for which borsh implementations can be derived. While the first step is quite straightforward, the second requires RawTrieNode::Branch variant being split into two: BranchNoValue and BranchWithValue. The main benefit of this is less code (the commit has delta of -68 lines) and API consistent with other serialised objects. However, this doesn’t come without downsides. Firstly, having separate BranchNoValue and BranchWithValue branches means that it’s now a bit more awkward to handle branch as a single case with common code paths having to be refactored. Secondly, one might imagine in the future a new representation for nodes which embed value. For example {4u8}{key_len:u32}{key}{value} might be added for a leaf. This would essentially mean that value comprises of the rest of encoded bytes. The issue for borsh is that it would like to know length of {value} before it reads it. Either redundant {value_len:u32} would need to be included or some hacks employed (namely not using borsh for RawTrieNodeWithSize and then consuming the rest of the reader when decoding RawTrieNode). Lastly, I’m not certain about performance implications. Borsh might actually be slower than hand-implemented decoder which operates on a slice. If this is actually the case I haven’t measured.
nikurt
pushed a commit
that referenced
this pull request
Apr 25, 2023
Replace Children::encode_into and decode methods by implementations of BorshSerializable and BorshDeserializable traits and with that change RawTrieNode into an enum for which borsh implementations can be derived. While the first step is quite straightforward, the second requires RawTrieNode::Branch variant being split into two: BranchNoValue and BranchWithValue. The main benefit of this is less code (the commit has delta of -68 lines) and API consistent with other serialised objects. However, this doesn’t come without downsides. Firstly, having separate BranchNoValue and BranchWithValue branches means that it’s now a bit more awkward to handle branch as a single case with common code paths having to be refactored. Secondly, one might imagine in the future a new representation for nodes which embed value. For example {4u8}{key_len:u32}{key}{value} might be added for a leaf. This would essentially mean that value comprises of the rest of encoded bytes. The issue for borsh is that it would like to know length of {value} before it reads it. Either redundant {value_len:u32} would need to be included or some hacks employed (namely not using borsh for RawTrieNodeWithSize and then consuming the rest of the reader when decoding RawTrieNode). Lastly, I’m not certain about performance implications. Borsh might actually be slower than hand-implemented decoder which operates on a slice. If this is actually the case I haven’t measured.
nikurt
pushed a commit
that referenced
this pull request
Apr 28, 2023
Replace Children::encode_into and decode methods by implementations of BorshSerializable and BorshDeserializable traits and with that change RawTrieNode into an enum for which borsh implementations can be derived. While the first step is quite straightforward, the second requires RawTrieNode::Branch variant being split into two: BranchNoValue and BranchWithValue. The main benefit of this is less code (the commit has delta of -68 lines) and API consistent with other serialised objects. However, this doesn’t come without downsides. Firstly, having separate BranchNoValue and BranchWithValue branches means that it’s now a bit more awkward to handle branch as a single case with common code paths having to be refactored. Secondly, one might imagine in the future a new representation for nodes which embed value. For example {4u8}{key_len:u32}{key}{value} might be added for a leaf. This would essentially mean that value comprises of the rest of encoded bytes. The issue for borsh is that it would like to know length of {value} before it reads it. Either redundant {value_len:u32} would need to be included or some hacks employed (namely not using borsh for RawTrieNodeWithSize and then consuming the rest of the reader when decoding RawTrieNode). Lastly, I’m not certain about performance implications. Borsh might actually be slower than hand-implemented decoder which operates on a slice. If this is actually the case I haven’t measured.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replace Children::encode_into and decode methods by implementations of
BorshSerializable and BorshDeserializable traits and with that change
RawTrieNode into an enum for which borsh implementations can be
derived. While the first step is quite straightforward, the second
requires RawTrieNode::Branch variant being split into two:
BranchNoValue and BranchWithValue.
The main benefit of this is less code (the commit has delta of -68
lines) and API consistent with other serialised objects. However,
this doesn’t come without downsides.
Firstly, having separate BranchNoValue and BranchWithValue branches
means that it’s now a bit more awkward to handle branch as a single
case with common code paths having to be refactored.
Secondly, one might imagine in the future a new representation for
nodes which embed value. For example {4u8}{key_len:u32}{key}{value}
might be added for a leaf. This would essentially mean that value
comprises of the rest of encoded bytes. The issue for borsh is that
it would like to know length of {value} before it reads it. Either
redundant {value_len:u32} would need to be included or some hacks
employed (namely not using borsh for RawTrieNodeWithSize and then
consuming the rest of the reader when decoding RawTrieNode).
Lastly, I’m not certain about performance implications. Borsh might
actually be slower than hand-implemented decoder which operates on
a slice. If this is actually the case I haven’t measured.