Skip to content
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

Optimize zero-value memory variable declarations using CALLDATACOPY #2144

Closed
iamdefinitelyahuman opened this issue Sep 6, 2020 · 0 comments · Fixed by #2174
Closed

Optimize zero-value memory variable declarations using CALLDATACOPY #2144

iamdefinitelyahuman opened this issue Sep 6, 2020 · 0 comments · Fixed by #2174
Labels
Optimization Issues related to compiler optimization

Comments

@iamdefinitelyahuman
Copy link
Contributor

iamdefinitelyahuman commented Sep 6, 2020

Description

A common pattern I use is to declare multiple memory variables with zero-values at the beginning of a function. For example:

@external
def foo():
    a: int128 = 0
    b: uint256[3] = empty(uint256[3])
    c: address = ZERO_ADDRESS

These intializations produce the following LLL:

[mstore, 320, 0],
[calldatacopy, 352, calldatasize, 96],
[mstore, 448, 0],

Which could be optimized to:

[calldatacopy, 320, calldatasize, 160]

How to Implement

  • After generating the LLL, look for sequential zero-value memory assignments or calldatacopy actions and merge them into a single calldatacopy.
  • It might also be possible to mutate the AST by moving all the AnnAssign nodes to the top of the function body (if the right-hand-side is a zero value).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Optimization Issues related to compiler optimization
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant