Skip to content

Conversation

JulianGCalderon
Copy link
Contributor

Avoid cloning constants when compiling hints

Description

By changing the compile_hint parameter type to Arc instead of Rc, we can reuse the constants that are already included in Program. This avoids cloning all the constants.

This PR is breaking, as the constants parameter of compile_hints was changed from Rc to Arc. This allows to reuse the already extracted constants, and not have to clone it.

By changing the compile_hint parameter type to `Arc` instead of `Rc`, we
can reuse the constants that are already included in `Program`. This
avoids cloning all the constants.

With this commit, there is a 9.8% performance increase when replaying
mainnet block 10000, compared to 2.5.0.
Copy link

github-actions bot commented Sep 25, 2025

**Hyper Thereading Benchmark results**




hyperfine -r 2 -n "hyper_threading_main threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_main' -n "hyper_threading_pr threads: 1" 'RAYON_NUM_THREADS=1 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 1
  Time (mean ± σ):     24.548 s ±  0.020 s    [User: 23.740 s, System: 0.805 s]
  Range (min … max):   24.534 s … 24.562 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     24.547 s ±  0.030 s    [User: 23.732 s, System: 0.813 s]
  Range (min … max):   24.526 s … 24.569 s    2 runs
 
Summary
  hyper_threading_pr threads: 1 ran
    1.00 ± 0.00 times faster than hyper_threading_main threads: 1




hyperfine -r 2 -n "hyper_threading_main threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_main' -n "hyper_threading_pr threads: 2" 'RAYON_NUM_THREADS=2 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 2
  Time (mean ± σ):     13.347 s ±  0.008 s    [User: 23.780 s, System: 0.875 s]
  Range (min … max):   13.342 s … 13.353 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     13.432 s ±  0.077 s    [User: 23.927 s, System: 0.851 s]
  Range (min … max):   13.378 s … 13.486 s    2 runs
 
Summary
  hyper_threading_main threads: 2 ran
    1.01 ± 0.01 times faster than hyper_threading_pr threads: 2




hyperfine -r 2 -n "hyper_threading_main threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_main' -n "hyper_threading_pr threads: 4" 'RAYON_NUM_THREADS=4 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 4
  Time (mean ± σ):     10.149 s ±  0.152 s    [User: 36.256 s, System: 0.993 s]
  Range (min … max):   10.041 s … 10.257 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     10.147 s ±  0.240 s    [User: 36.063 s, System: 1.015 s]
  Range (min … max):    9.977 s … 10.316 s    2 runs
 
Summary
  hyper_threading_pr threads: 4 ran
    1.00 ± 0.03 times faster than hyper_threading_main threads: 4




hyperfine -r 2 -n "hyper_threading_main threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_main' -n "hyper_threading_pr threads: 6" 'RAYON_NUM_THREADS=6 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 6
  Time (mean ± σ):     10.041 s ±  0.201 s    [User: 36.419 s, System: 1.018 s]
  Range (min … max):    9.898 s … 10.183 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     10.065 s ±  0.119 s    [User: 36.074 s, System: 1.017 s]
  Range (min … max):    9.981 s … 10.150 s    2 runs
 
Summary
  hyper_threading_main threads: 6 ran
    1.00 ± 0.02 times faster than hyper_threading_pr threads: 6




hyperfine -r 2 -n "hyper_threading_main threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_main' -n "hyper_threading_pr threads: 8" 'RAYON_NUM_THREADS=8 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 8
  Time (mean ± σ):      9.825 s ±  0.011 s    [User: 37.025 s, System: 1.038 s]
  Range (min … max):    9.817 s …  9.833 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):      9.826 s ±  0.079 s    [User: 37.014 s, System: 1.021 s]
  Range (min … max):    9.770 s …  9.882 s    2 runs
 
Summary
  hyper_threading_main threads: 8 ran
    1.00 ± 0.01 times faster than hyper_threading_pr threads: 8




hyperfine -r 2 -n "hyper_threading_main threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_main' -n "hyper_threading_pr threads: 16" 'RAYON_NUM_THREADS=16 ./hyper_threading_pr'
Benchmark 1: hyper_threading_main threads: 16
  Time (mean ± σ):     10.056 s ±  0.102 s    [User: 37.122 s, System: 1.102 s]
  Range (min … max):    9.984 s … 10.127 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):      9.763 s ±  0.008 s    [User: 37.188 s, System: 1.114 s]
  Range (min … max):    9.758 s …  9.769 s    2 runs
 
Summary
  hyper_threading_pr threads: 16 ran
    1.03 ± 0.01 times faster than hyper_threading_main threads: 16


Copy link

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.079 ± 0.011 2.068 2.105 1.00
head big_factorial 2.103 ± 0.078 2.057 2.322 1.01 ± 0.04
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.006 ± 0.019 1.976 2.037 1.00
head big_fibonacci 2.023 ± 0.013 1.999 2.040 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.216 ± 0.117 7.023 7.482 1.00
head blake2s_integration_benchmark 7.487 ± 0.051 7.400 7.538 1.04 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.122 ± 0.027 2.087 2.183 1.00
head compare_arrays_200000 2.130 ± 0.021 2.112 2.183 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.395 ± 0.007 1.387 1.410 1.00
head dict_integration_benchmark 1.398 ± 0.009 1.388 1.423 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.182 ± 0.007 1.172 1.191 1.00
head field_arithmetic_get_square_benchmark 1.213 ± 0.006 1.207 1.223 1.03 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.266 ± 0.075 7.148 7.391 1.00
head integration_builtins 7.747 ± 0.599 7.494 9.445 1.07 ± 0.08
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 7.315 ± 0.108 7.159 7.430 1.00
head keccak_integration_benchmark 7.621 ± 0.055 7.563 7.716 1.04 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.093 ± 0.014 2.077 2.120 1.00
head linear_search 2.129 ± 0.007 2.119 2.137 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.476 ± 0.015 1.459 1.506 1.00
head math_cmp_and_pow_integration_benchmark 1.478 ± 0.007 1.469 1.489 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.427 ± 0.013 1.412 1.450 1.00
head math_integration_benchmark 1.433 ± 0.008 1.423 1.446 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.201 ± 0.016 1.178 1.233 1.01 ± 0.01
head memory_integration_benchmark 1.188 ± 0.006 1.179 1.198 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.505 ± 0.006 1.496 1.512 1.00
head operations_with_data_structures_benchmarks 1.523 ± 0.011 1.504 1.539 1.01 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 524.6 ± 2.4 520.9 528.8 1.00
head pedersen 525.0 ± 3.3 520.3 530.3 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 597.4 ± 2.3 594.8 600.9 1.00 ± 0.00
head poseidon_integration_benchmark 594.6 ± 1.4 592.5 597.4 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.755 ± 0.006 1.745 1.766 1.00
head secp_integration_benchmark 1.782 ± 0.009 1.766 1.794 1.02 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 643.0 ± 4.4 636.9 651.4 1.03 ± 0.01
head set_integration_benchmark 621.3 ± 2.0 618.2 624.6 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.075 ± 0.038 4.038 4.167 1.00
head uint256_integration_benchmark 4.216 ± 0.041 4.181 4.323 1.03 ± 0.01

Copy link

codecov bot commented Sep 25, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.68%. Comparing base (958ae7e) to head (3ac66b8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2208      +/-   ##
==========================================
- Coverage   96.68%   96.68%   -0.01%     
==========================================
  Files         104      104              
  Lines       44027    44026       -1     
==========================================
- Hits        42566    42565       -1     
  Misses       1461     1461              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JulianGCalderon JulianGCalderon marked this pull request as ready for review September 25, 2025 17:29
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.

1 participant