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

perf: levenshtein optimization #3780

Merged
merged 5 commits into from
Feb 14, 2024

Conversation

charles-cooper
Copy link
Member

@charles-cooper charles-cooper commented Feb 13, 2024

What I did

How I did it

How to verify it

find some large contract (e.g. CurveStableSwapNG.vy), try vyc -f annotated_ast and vyc -f bytecode.

# master
$ time vyc tmp/CurveStableSwap-0.4.0.vy >/dev/null

real	0m4.467s
user	0m4.259s
sys	0m0.206s

$ time vyc -f annotated_ast tmp/CurveStableSwap-0.4.0.vy >/dev/null

real	0m1.681s
user	0m1.625s
sys	0m0.058s

# this branch
$ time vyc tmp/CurveStableSwap-0.4.0.vy >/dev/null

real	0m4.150s
user	0m3.899s
sys	0m0.250s

$ time vyc -f annotated_ast tmp/CurveStableSwap-0.4.0.vy >/dev/null

real	0m1.427s
user	0m1.390s
sys	0m0.039s

Commit message

optimize compile time. `levenshtein` is a hotspot since it is called a
lot during type analysis to construct exceptions (which are then caught
as part of the validation routines). this commit delays calling
`levenshtein` until the last minute, and also adds a mechanism to
`VyperException` so that hints can be constructed lazily in general.

on a couple test contracts, compilation time comes down 7%. however, as
a portion of the time spent in the frontend, compilation time comes down
20-30%. this will become important as projects become larger (that is,
many imports but only some functions are actually present in codegen)
and compilation time is dominated by the frontend.

Description for the changelog

Cute Animal Picture

image

vyper/exceptions.py Fixed Show fixed Hide fixed
vyper/levenshtein_utils.py Fixed Show fixed Hide fixed
vyper/levenshtein_utils.py Fixed Show fixed Hide fixed
@codecov-commenter
Copy link

codecov-commenter commented Feb 14, 2024

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (d372378) 84.99% compared to head (4d717d0) 84.98%.
Report is 1 commits behind head on master.

Files Patch % Lines
vyper/exceptions.py 71.42% 1 Missing and 1 partial ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3780      +/-   ##
==========================================
- Coverage   84.99%   84.98%   -0.01%     
==========================================
  Files          92       92              
  Lines       13702    13709       +7     
  Branches     3074     3077       +3     
==========================================
+ Hits        11646    11651       +5     
- Misses       1569     1570       +1     
- Partials      487      488       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

vyper/exceptions.py Fixed Show fixed Hide fixed
vyper/levenshtein_utils.py Fixed Show fixed Hide fixed
defer the call to `levenshtein` until we need an error message
@charles-cooper charles-cooper marked this pull request as ready for review February 14, 2024 01:56
@charles-cooper charles-cooper changed the title fix perf: levenshtein optimization perf: levenshtein optimization Feb 14, 2024
@charles-cooper
Copy link
Member Author

by the way, as of this PR, compilation time has come down 45% since v0.3.10!

# this PR
$ time vyc tmp/CurveStableSwapNG-0.4.0.vy >/dev/null

real	0m3.960s
user	0m3.810s
sys	0m0.148s

# v0.3.10
$ time vyc tmp/CurveStableSwapNG.vy >/dev/null

real	0m7.683s
user	0m7.474s
sys	0m0.206s

$ python
Python 3.11.7 (main, Dec  8 2023, 18:56:58) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 4.6/7.7
0.5974025974025974

@charles-cooper charles-cooper merged commit 4b4e188 into vyperlang:master Feb 14, 2024
84 checks passed
@charles-cooper charles-cooper deleted the fix/perf-levenshtein branch February 14, 2024 03:26
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.

4 participants