-
Notifications
You must be signed in to change notification settings - Fork 185
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
refactor(store): optimize Schema #1252
Conversation
🦋 Changeset detectedLatest commit: bade5cb The changes in this PR will be included in the next version bump. This PR includes changesets to release 27 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
great work! |
"file": "test/Schema.t.sol", | ||
"test": "testGetNumDynamicFields", | ||
"name": "get number of dynamic fields from schema", | ||
"gasUsed": 74 | ||
"gasUsed": 68 | ||
}, | ||
{ | ||
"file": "test/Schema.t.sol", | ||
"test": "testGetNumFields", | ||
"name": "get number of all fields from schema", | ||
"gasUsed": 34 | ||
}, | ||
{ | ||
"file": "test/Schema.t.sol", | ||
"test": "testGetNumStaticFields", | ||
"name": "get number of static fields from schema", | ||
"gasUsed": 85 | ||
"gasUsed": 79 |
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.
you may note that getting both dynamic and static is 2x cheaper than getting them separately. This is wrong and related to #1267
I wonder if these tests should be removed to avoid confusion?
validate
- only did a few obvious tweaks there)encode
can still be made much better by replacingSchemaType
with a static length, but that's another PRencode
optimization would be to inline it in table libs, but not sure it's worth it, will think about it when I get to table libsCase study of
encode
's gas optimizations, this function is particularly interesting. (the screenshot shows code before this PR, changes are mostly 1:1, but within the loop I use gas per average iteration, which depends on Schema composition, and I used somewhat different schemas before and after, expect it to vary by 5-10 gas. 56->47 could be mostly noise for example.)Note that gas within the loop is more impactful, as it's multiplied by the number of schema fields.