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

Thv/faster compilation #326

Merged
merged 2 commits into from
Sep 19, 2024
Merged

Thv/faster compilation #326

merged 2 commits into from
Sep 19, 2024

Conversation

Sword-Smith
Copy link
Collaborator

Reduces compilation time by 80-90 % by:

  • executing build-script code with opt-level=3
  • caching node-degrees in ConstraintCircuitMonad::pick_node_to_substitute

A benchmark of the degree-lowering code on the thv/degree-lowering-hardening branch gave us the false impression that degree-lowering was only about 20 seconds. But that was when the code ran with opt-level=3 which is standard for benchmarks. The default for build scripts is opt-level=0. Changing the opt-level to 3 speeds up the build script by a factor six. And a further optimization in the degree-lowering code where the node-degrees are cached in the function that is the bottle-neck, as opposed to recalculated many times, gives another 30 % reduction in build times.

@Sword-Smith
Copy link
Collaborator Author

Sword-Smith commented Sep 18, 2024

Build times on Tanngrisnir (my new desktop):
master: 3 minutes 4 seconds
this branch: 19.3 seconds.

Reduction in compilation time: 89.5 %.

Copy link
Member

@jan-ferdinand jan-ferdinand left a comment

Choose a reason for hiding this comment

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

Good stuff! I left a few {sugg, qu}estions inline.

triton-constraint-circuit/src/lib.rs Outdated Show resolved Hide resolved
triton-constraint-circuit/src/lib.rs Outdated Show resolved Hide resolved
triton-constraint-circuit/src/lib.rs Outdated Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
The degree-lowering step takes up 90-95 % of the total build time. The
degree-lowering code is executed in the build script `build.rs`. By
default, Cargo compiles build scripts in debug mode with optimization
level 0. Overriding this default leads to a 6-times speedup in the
compilation time on my machine (mjolnir), as the build script execution
goes from taking ~150s to ~25s. Running from a clean slate (using
`cargo clean`), this change results in a speedup from 2m 29s to 52.2s.
Cache node degrees in the `pick_node_to_substitute` function which was
found to be the bottle-neck in the build script. This caching shaves off
38 % of the time it takes to degree-lower, and 30 % of total build time
of Triton VM.

Measurements on my machine (mjolnir):
degree-lowering step in build script:
Before caching degrees:
- 22.024172299s
- 21.938811734s

After caching:
- 13.657397858s
- 13.753980057s

Total time to build triton-vm after change to
`triton-constraint-circuit/src/lib.rs`:
Before caching degrees:
- 26.13s
- 26.74s

After caching:
- 18.63s
- 18.65s
@Sword-Smith Sword-Smith merged commit 6496a74 into master Sep 19, 2024
4 checks passed
@jan-ferdinand jan-ferdinand deleted the thv/faster-compilation branch September 19, 2024 11: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.

2 participants