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

add some small LLL optimizations #2493

Merged
merged 6 commits into from
Oct 20, 2021
Merged

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Oct 19, 2021

What I did

Add a couple peephole assembly optimizations and an LLL optimization for truthy sequences. Code size for three large-ish contracts comes down about 2.5%.

How I did it

How to verify it

Use the vyper-lll tool to inspect the output of this LLL

(seq
 (assert (eq 1 2))
 (assert (ne 1 2))
 (if (ne 1 2) (revert 0 0))
 )

Description for the changelog

Optimize truthy sequences and peephole stack operations.

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

vyper/cli/vyper_lll.py Show resolved Hide resolved
Comment on lines 679 to 684
if assembly[i:i+3] == ["DUP1", "SWAP1", "POP"]:
del assembly[i:i+2]
continue
if assembly[i:i+3] == ["SWAP1", "POP", "POP"]:
del assembly[i]
continue
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a little comment explaining why the optimization works

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codecov-commenter
Copy link

Codecov Report

Merging #2493 (e27c938) into master (93a9579) will decrease coverage by 1.15%.
The diff coverage is 92.85%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2493      +/-   ##
==========================================
- Coverage   84.60%   83.44%   -1.16%     
==========================================
  Files          93       93              
  Lines        9228     9133      -95     
  Branches     2086     2087       +1     
==========================================
- Hits         7807     7621     -186     
- Misses        935     1023      +88     
- Partials      486      489       +3     
Impacted Files Coverage Δ
vyper/cli/vyper_lll.py 0.00% <0.00%> (ø)
vyper/lll/compile_lll.py 94.48% <100.00%> (+0.13%) ⬆️
vyper/lll/optimizer.py 84.07% <100.00%> (ø)
vyper/ast/annotation.py 87.87% <0.00%> (-6.82%) ⬇️
vyper/semantics/types/value/numeric.py 80.21% <0.00%> (-5.81%) ⬇️
vyper/builtin_functions/functions.py 83.72% <0.00%> (-5.57%) ⬇️
vyper/old_codegen/expr.py 74.02% <0.00%> (-5.08%) ⬇️
vyper/ast/validation.py 68.88% <0.00%> (-4.45%) ⬇️
vyper/ovm/transpile_lll.py 61.33% <0.00%> (-2.65%) ⬇️
vyper/ast/nodes.py 92.06% <0.00%> (-1.53%) ⬇️
... and 15 more

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 93a9579...e27c938. Read the comment docs.

@fubuloubu fubuloubu merged commit 64ccce6 into vyperlang:master Oct 20, 2021
@charles-cooper charles-cooper deleted the misc_opts branch October 20, 2021 02:05
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