Add calldata located variables.#1499
Merged
Merged
Conversation
Contributor
Author
|
@charles-cooper could you give this a look through? :) |
Member
|
Sure! I will have to get to it next week, though. |
Contributor
Author
|
Sure! I reckon it's mostly OK, I checked it over when it wasn't 4 AM ... and it still looked good hehe |
| name=arg.name, | ||
| pos=default_arg_pos, | ||
| typ=arg.typ, | ||
| mutable=False, |
Member
There was a problem hiding this comment.
for clarity, could set location explicitly here
Member
|
@jacqueswww this looks pretty good, I didn't see the code that copies dynamic data to memory though? Could you help point it out to me? |
jacqueswww
commented
Jul 4, 2019
| @@ -138,12 +135,29 @@ def parse_public_function(code: ast.FunctionDef, | |||
| mem_pos, _ = context.memory_allocator.increase_memory(32 * get_size_of_type(arg.typ)) | |||
| context.vars[arg.name] = VariableRecord(arg.name, mem_pos, arg.typ, False) | |||
Contributor
Author
There was a problem hiding this comment.
@charles-cooper The byte-arrays are copied into memory here.
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
Fixes #1381.
This is an optimisation I am glad I finally got to make! Basically we were copying variables to memory unnecessarily, by using the calldata directly one not only gets better speed - but also ensures on the EVM level the variables are read-only (yes we had a test that actually was altering a parameter in a tuple assign).
This changes affects these these function parameter types.
Note: Turned out ByteArrays were too difficult optimise, especially when they tend to have to be packed, which one would have to just allocate them again. Also one looses out not being able to always re-use the identity / mem copy contract.
Taking some files from the examples directory:
Blind Auction -> 73 % less bytecode (!!!)
ERC20 -> 4.9 % less bytecode
ERC720 -> 6.3% less bytecode
Additionally we save runtime costs because we skip 'n full N of mstore (memory growth) on each call.
Also private calls tend to be much cheaper on average, because the in-memory context is smaller.
How I did it
Used a lot of coffee ☕
How to verify it
Check commits, play with your own contracts.
Description for the changelog
Bytecode & Runtime optimisation for function parameters.
Cute Animal Picture