-
Notifications
You must be signed in to change notification settings - Fork 100
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
ManagedBufferBuilder refactor & remove cache #1540
Merged
Merged
+884
−76
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
Coverage SummaryTotals
FilesExpand
|
Contract comparison - from 3aa7d70 to ed8e28e
|
BiancaIalangi
approved these changes
Apr 8, 2024
mihaicalinluca
approved these changes
Apr 8, 2024
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.
Refactored the
ManagedBufferBuilder
, and separated its implementation. This builder is primarily used to concatenate nested encodings, especially for structures and vectors.There are 2 ways to do it:
The cached one used to be the only implementation, but it was causing troubles in Kasmer. I decided to remove it, but left in place the possibility to switch it back in.
The thing is, the cached version adds around 800-900 bytes to the contract, so everything is a little more expensive. Is it ever worth it?
I decided to benchmark it (crudely, might be nice to have better benchmarking tools). From playing around it looks like:
Another caveat: the cached version only helps when serializing bytes, such as serialized u32. When serializing managed buffers for instance, the 2 versions do the same. So the caching benefit is even less.
I would conclude that simpler is better in 99% of cases, and the cached version should remain an exotic feature, rather than the default.