Reduce contract code size by wrapping clamping of args into a loop#1488
Merged
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): |
Member
There was a problem hiding this comment.
when are datapos and mempos lists?
Contributor
Author
There was a problem hiding this comment.
When we have a list of lists! This was revealed to me in one of the test cases.
Contributor
There was a problem hiding this comment.
@siraben I think you should just use get_size_of_type(typ) here instead this will support above cases as well.
jacqueswww
suggested changes
Jul 4, 2019
| 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): |
Contributor
There was a problem hiding this comment.
@siraben I think you should just use get_size_of_type(typ) here instead this will support above cases as well.
Contributor
|
Merging now, will add get_size_of_type separately. |
This file contains hidden or 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
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.
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_clamperto 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