Skip to content

Conversation

JulianGCalderon
Copy link
Contributor

Add support for Hint Data caching

This PR adds support for caching the compiled hint data between executions of the same contract.

I benchmarked some transactions and found a performance improvement of 20% 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 set_hint_data function.

  • This only works without the extensive_hints feature, which is a problem due to the way Cargo unifies features.

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.141 ± 0.010 2.127 2.164 1.01 ± 0.01
head big_factorial 2.125 ± 0.014 2.104 2.145 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.058 ± 0.014 2.038 2.086 1.00
head big_fibonacci 2.064 ± 0.022 2.030 2.116 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.668 ± 0.022 7.642 7.701 1.00
head blake2s_integration_benchmark 7.713 ± 0.107 7.623 7.993 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.211 ± 0.040 2.172 2.284 1.01 ± 0.02
head compare_arrays_200000 2.200 ± 0.017 2.172 2.228 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.425 ± 0.008 1.412 1.436 1.00
head dict_integration_benchmark 1.432 ± 0.008 1.418 1.442 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.227 ± 0.007 1.215 1.237 1.00
head field_arithmetic_get_square_benchmark 1.239 ± 0.039 1.221 1.348 1.01 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.781 ± 0.035 7.748 7.868 1.00
head integration_builtins 7.803 ± 0.045 7.737 7.856 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 7.976 ± 0.069 7.906 8.129 1.00 ± 0.01
head keccak_integration_benchmark 7.973 ± 0.053 7.908 8.071 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.164 ± 0.012 2.150 2.184 1.00 ± 0.01
head linear_search 2.163 ± 0.012 2.145 2.177 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.510 ± 0.005 1.503 1.515 1.00
head math_cmp_and_pow_integration_benchmark 1.519 ± 0.009 1.504 1.531 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.465 ± 0.016 1.453 1.507 1.00 ± 0.02
head math_integration_benchmark 1.465 ± 0.017 1.452 1.496 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.226 ± 0.019 1.209 1.274 1.01 ± 0.02
head memory_integration_benchmark 1.219 ± 0.015 1.201 1.253 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.567 ± 0.004 1.562 1.577 1.00 ± 0.01
head operations_with_data_structures_benchmarks 1.562 ± 0.010 1.549 1.585 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 528.7 ± 1.7 525.3 530.7 1.00 ± 0.00
head pedersen 527.7 ± 1.6 525.5 530.1 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 618.9 ± 4.7 612.3 627.7 1.00
head poseidon_integration_benchmark 621.1 ± 5.6 610.8 630.4 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.838 ± 0.018 1.825 1.887 1.00
head secp_integration_benchmark 1.839 ± 0.015 1.827 1.873 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 609.1 ± 5.9 604.0 622.5 1.01 ± 0.01
head set_integration_benchmark 604.2 ± 2.0 601.1 607.2 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.235 ± 0.036 4.199 4.315 1.00
head uint256_integration_benchmark 4.266 ± 0.034 4.241 4.348 1.01 ± 0.01

Copy link

codecov bot commented Oct 3, 2025

Codecov Report

❌ Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.65%. Comparing base (dbea70a) to head (637a767).
⚠️ Report is 1 commits behind head on opt-vm.

Files with missing lines Patch % Lines
vm/src/vm/runners/cairo_runner.rs 50.00% 4 Missing ⚠️
vm/src/utils.rs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           opt-vm    #2220      +/-   ##
==========================================
- Coverage   96.66%   96.65%   -0.02%     
==========================================
  Files         103      103              
  Lines       43682    43694      +12     
==========================================
+ Hits        42227    42234       +7     
- Misses       1455     1460       +5     

☔ 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