Skip to content

Conversation

JulianGCalderon
Copy link
Contributor

Add support for caching program segment

I benchmarked some transactions and found a performance improvement of 3% when running old transactions (Cairo 0).

  • The cache used is really simple (thread local). A proper cache for hint data would have more overhead than what I used.
  • In my benchmark I ensured that everything is cached beforehand. This won't happen in an actual execution.

Some limitations:

  • This PR is not breaking, but to achieve this I had to expose an unsafe API. See safety notes on the load_cached_program function.

  • I had to make the memory public, so that the user is able to cache the program segment. We could add a wrapper type to avoid exposing the memory.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

Copy link

github-actions bot commented Oct 3, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.134 ± 0.011 2.121 2.160 1.00 ± 0.01
head big_factorial 2.132 ± 0.008 2.123 2.146 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.052 ± 0.010 2.039 2.071 1.00
head big_fibonacci 2.061 ± 0.018 2.044 2.106 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.653 ± 0.022 7.613 7.676 1.00
head blake2s_integration_benchmark 7.653 ± 0.079 7.561 7.764 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.177 ± 0.019 2.154 2.222 1.00
head compare_arrays_200000 2.195 ± 0.006 2.187 2.204 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.434 ± 0.007 1.421 1.444 1.00 ± 0.01
head dict_integration_benchmark 1.430 ± 0.014 1.415 1.466 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.230 ± 0.005 1.223 1.243 1.01 ± 0.01
head field_arithmetic_get_square_benchmark 1.221 ± 0.007 1.214 1.232 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.813 ± 0.161 7.720 8.263 1.00 ± 0.03
head integration_builtins 7.798 ± 0.150 7.666 8.147 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.015 ± 0.104 7.910 8.239 1.00
head keccak_integration_benchmark 8.060 ± 0.114 7.871 8.247 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.178 ± 0.032 2.154 2.265 1.00
head linear_search 2.192 ± 0.075 2.153 2.394 1.01 ± 0.04
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.507 ± 0.008 1.495 1.521 1.00 ± 0.01
head math_cmp_and_pow_integration_benchmark 1.504 ± 0.006 1.498 1.514 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.455 ± 0.005 1.446 1.463 1.00 ± 0.01
head math_integration_benchmark 1.450 ± 0.007 1.444 1.467 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.206 ± 0.006 1.195 1.215 1.00
head memory_integration_benchmark 1.212 ± 0.013 1.199 1.241 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.572 ± 0.012 1.560 1.598 1.00 ± 0.01
head operations_with_data_structures_benchmarks 1.564 ± 0.006 1.558 1.578 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 529.3 ± 1.6 526.6 531.6 1.00
head pedersen 531.0 ± 1.4 529.4 533.1 1.00 ± 0.00
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 621.9 ± 2.8 617.2 625.5 1.00
head poseidon_integration_benchmark 625.8 ± 6.4 620.3 642.5 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.840 ± 0.006 1.836 1.855 1.00 ± 0.01
head secp_integration_benchmark 1.837 ± 0.012 1.824 1.864 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 631.7 ± 2.3 628.6 634.7 1.00 ± 0.00
head set_integration_benchmark 629.2 ± 1.6 626.8 632.2 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.246 ± 0.023 4.218 4.291 1.00
head uint256_integration_benchmark 4.252 ± 0.031 4.212 4.289 1.00 ± 0.01

Copy link

codecov bot commented Oct 3, 2025

Codecov Report

❌ Patch coverage is 41.02564% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.60%. Comparing base (065c8f4) to head (4a6c52f).

Files with missing lines Patch % Lines
vm/src/vm/vm_memory/memory.rs 5.26% 18 Missing ⚠️
vm/src/vm/runners/cairo_runner.rs 75.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            2.x.y    #2221      +/-   ##
==========================================
- Coverage   96.66%   96.60%   -0.06%     
==========================================
  Files         103      103              
  Lines       43646    43681      +35     
==========================================
+ Hits        42191    42199       +8     
- Misses       1455     1482      +27     

☔ 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.

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