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

feat: memoize compiler verification per worker #196

Merged
merged 3 commits into from
Jun 8, 2022

Conversation

kanej
Copy link
Member

@kanej kanej commented Jun 2, 2022

This PR speeds up the solc compile step of validation.

Previously, after preprocessing to build the solc input object, to compile we ran the TASK_COMPILE_SOLIDITY_COMPILE task. This has three subtasks:

  • TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD
  • TASK_COMPILE_SOLIDITY_RUN_SOLCJS
  • TASK_COMPILE_SOLIDITY_RUN_SOLC

The build subtask checks if the compiler for the given version is downloaded (downloading it if it is not), then verifies the checksum of the file. The solc or solcjs tasks (the actual solc compilation) are then run depending on which compiler was downloaded.

The build task adds hundreds of millisecond to a validation run (dwarfing the actual solc compile time).

This PR pulls up the subtasks of TASK_COMPILE_SOLIDITY_COMPILE and memoizes the results of TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD using a new compilerMetadataCache entry in the workerState of the worker process.

The first build job in a worker for a particular solc version will take the cost of the compiler verification, but all subsequent build jobs for that worker will avoid it, speeding up validation.

@kanej kanej requested a review from alcuadrado June 2, 2022 15:24
@codecov-commenter
Copy link

codecov-commenter commented Jun 2, 2022

Codecov Report

Merging #196 (2c686e4) into development (d663e90) will increase coverage by 0.56%.
The diff coverage is n/a.

❗ Current head 2c686e4 differs from pull request most recent head 405c1fb. Consider uploading reports for the commit 405c1fb to get more accurate results

@@               Coverage Diff               @@
##           development     #196      +/-   ##
===============================================
+ Coverage        66.43%   67.00%   +0.56%     
===============================================
  Files              163      163              
  Lines             3802     3825      +23     
  Branches           659      664       +5     
===============================================
+ Hits              2526     2563      +37     
+ Misses            1057     1043      -14     
  Partials           219      219              
Impacted Files Coverage Δ
...rc/services/validation/worker/build/solcCompile.ts 100.00% <0.00%> (ø)
...vices/validation/worker/build/buildInputsToSolc.ts 98.38% <0.00%> (+0.51%) ⬆️
src/services/documents/onDidChangeWatchedFiles.ts 100.00% <0.00%> (+82.35%) ⬆️

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 d663e90...405c1fb. Read the comment docs.

kanej added 3 commits June 7, 2022 11:47
The solc compile task is made up of two subtasks: build, which checks
the compiler, and run solc.

These have both been pulled up to worker level, in prep for caching
build.
Move the build subtask to the preprocessing steps (rather than the solc
compile phase).
The build check step is expensive and only needs to happen once per solc
version. The worker now tracks which compilers have been downloaded and
checked in `compilerMetadataCache` and returns the memoized result if
available based on solc version.
@kanej kanej force-pushed the feat/split-solc-build-compile branch from 405c1fb to ef59b41 Compare June 7, 2022 10:51
@kanej kanej merged commit 2c12063 into development Jun 8, 2022
@kanej kanej deleted the feat/split-solc-build-compile branch June 8, 2022 13:41
@kanej kanej mentioned this pull request Jun 8, 2022
kanej added a commit that referenced this pull request Jun 8, 2022
The solc compile task is made up of two subtasks: build, which checks
the compiler, and run solc.

These have both been pulled up from hardhat to the worker level, the build
subtask has been moved to the preprocessing steps (rather than the solc
compile phase).

The build check step is expensive and only needs to happen once per solc
version. The worker now tracks which compilers have been downloaded and
checked in `compilerMetadataCache` and returns the memoized result if
available based on solc version.
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.

2 participants