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

Reorder functions within the bytecode #2303

Merged

Conversation

iamdefinitelyahuman
Copy link
Contributor

What I did

Reorder functions within the bytecode and refactor how the function selector is checked.

How I did it

Functions were previous sequenced in the same way as they are found in the source. Internal functions were jumped over following an inefficient PUSH1 0x0 ISZEZO check.

This PR places all internal functions after the fallback, so they cannot be reached without being explicitely jumped to from an internal function. Thus, all the jumping logic can be removed and the bytecode size reduced.

The function selector itself was previous written to memory with offset 0, and loaded onto the stack for every comparison. This PR modifies the process so that the selector is kept on the stack and compared via DUP operations rather than repeated MLOAD. Less bytecode, less gas.

How to verify it

Run the tests, see that nothing has broken.

Cute Animal Picture

Coming soon

@iamdefinitelyahuman iamdefinitelyahuman marked this pull request as ready for review February 15, 2021 12:52
@codecov-io
Copy link

Codecov Report

Merging #2303 (c22c081) into master (fbd6880) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2303      +/-   ##
==========================================
- Coverage   85.82%   85.79%   -0.04%     
==========================================
  Files          85       85              
  Lines        8546     8549       +3     
  Branches     2036     2039       +3     
==========================================
  Hits         7335     7335              
- Misses        728      730       +2     
- Partials      483      484       +1     
Impacted Files Coverage Δ
vyper/compiler/utils.py 96.42% <100.00%> (+0.13%) ⬆️
...er/function_definitions/parse_external_function.py 100.00% <100.00%> (ø)
...er/function_definitions/parse_internal_function.py 97.89% <100.00%> (-0.05%) ⬇️
vyper/parser/function_definitions/utils.py 100.00% <100.00%> (ø)
vyper/parser/parser.py 81.81% <100.00%> (+0.64%) ⬆️
vyper/functions/functions.py 89.25% <0.00%> (-0.40%) ⬇️

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 fbd6880...095d5f8. Read the comment docs.

@fubuloubu fubuloubu merged commit 1358621 into vyperlang:master Feb 16, 2021
@iamdefinitelyahuman iamdefinitelyahuman deleted the optimize-func-selectors branch April 20, 2021 18:49
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