-
-
Notifications
You must be signed in to change notification settings - Fork 804
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
Reduce contract code size by wrapping clamping of args into a loop #1488
Conversation
Co-Authored-By: Charles Cooper <cooper.charles.m@gmail.com>
for i in range(typ.count): | ||
offset = get_size_of_type(typ.subtype) * 32 * i | ||
o.append(make_arg_clamper(datapos + offset, mempos + offset, typ.subtype, is_init)) | ||
if typ.count > 5 or (type(datapos) is list and type(mempos) is list): |
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.
when are datapos
and mempos
lists?
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.
When we have a list of lists! This was revealed to me in one of the test cases.
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.
which test case?
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.
@siraben I think you should just use get_size_of_type(typ) here instead this will support above cases as well.
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.
LGTM. Just one change in the if statement.
for i in range(typ.count): | ||
offset = get_size_of_type(typ.subtype) * 32 * i | ||
o.append(make_arg_clamper(datapos + offset, mempos + offset, typ.subtype, is_init)) | ||
if typ.count > 5 or (type(datapos) is list and type(mempos) is list): |
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.
@siraben I think you should just use get_size_of_type(typ) here instead this will support above cases as well.
Merging now, will add get_size_of_type separately. |
What I did
Reduced contract code size due to codegen of run-time type checking of list elements.
How I did it
Changed
make_arg_clamper
to generate an LLL loop instead of recursing over the list elements, when there are more than 5 elements in the list.All the tests pass.
How to verify it
Compile the following contract.
Old code size (bytes): 55340
New code size (bytes): 17474
This PR combined with #1486 reduces the code size down to a whopping 1644 bytes
Cute Animal Picture