Skip to content

Optimize calldataload#2352

Merged
fubuloubu merged 2 commits into
vyperlang:masterfrom
iamdefinitelyahuman:optimize-calldataload
Apr 15, 2021
Merged

Optimize calldataload#2352
fubuloubu merged 2 commits into
vyperlang:masterfrom
iamdefinitelyahuman:optimize-calldataload

Conversation

@iamdefinitelyahuman
Copy link
Copy Markdown
Contributor

@iamdefinitelyahuman iamdefinitelyahuman commented Apr 14, 2021

What I did

Optimize how calldata is loaded into memory.

How I did it

Within optimizer.py, look for sequential instructions of e.g.

[mstore, 864, [calldataload, 4]],
[mstore, 896, [calldataload, 36]],
[mstore, 928, [calldataload, 68]],

This can be optimized to:

[calldatacopy 864, 4, 32 * 3]

The optimization is applied with the same logic we use to optimize memory-zeroing actions:

  1. Look for sequential mstore instructions that reference sequential calldata locations.
  2. Merge them into a single calldatacopy

How to verify it

Run the tests. I didn't add any new specific cases, but this optimization is applied anywhere multiple input args are taken by an external function so if it weren't working we'd see things failing everywhere.

Cute Animal Picture

image

@codecov-io
Copy link
Copy Markdown

codecov-io commented Apr 14, 2021

Codecov Report

Merging #2352 (b0033f7) into master (2eeb27f) will increase coverage by 0.04%.
The diff coverage is 98.27%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2352      +/-   ##
==========================================
+ Coverage   85.84%   85.89%   +0.04%     
==========================================
  Files          90       90              
  Lines        8791     8820      +29     
  Branches     2097     2103       +6     
==========================================
+ Hits         7547     7576      +29     
  Misses        755      755              
  Partials      489      489              
Impacted Files Coverage Δ
vyper/optimizer.py 86.16% <98.27%> (+3.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2eeb27f...b0033f7. Read the comment docs.

@fubuloubu fubuloubu self-requested a review April 14, 2021 14:45
@fubuloubu fubuloubu merged commit 3af89b5 into vyperlang:master Apr 15, 2021
@iamdefinitelyahuman iamdefinitelyahuman deleted the optimize-calldataload branch April 15, 2021 21:44
skellet0r added a commit to skellet0r/curve-contract that referenced this pull request Apr 19, 2021
Additional improvements to mitigate memory corruption bug in vyper.
Additional optimizations.

vyperlang/vyper#2345
vyperlang/vyper#2350
vyperlang/vyper#2352
skellet0r added a commit to skellet0r/curve-contract that referenced this pull request Apr 29, 2021
Additional improvements to mitigate memory corruption bug in vyper.
Additional optimizations.

vyperlang/vyper#2345
vyperlang/vyper#2350
vyperlang/vyper#2352
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants