Skip to content

Conversation

DiegoCivi
Copy link
Contributor

@DiegoCivi DiegoCivi commented Aug 8, 2025

The function u384_integer_to_struct() was building MLIR code each time it was being called. In an effort to reduce compilation times, we wanted to see if by reducing the MLIR generated we could achieve this. This PR introduces an MLIR function that is only declared once so its code is not generated multiple times each time it is needed.

Benchmarks

Main column contains the compilation times of the main branch (ref -> which includes the optimization done in #1348) and the Branch column contains the compilation times of this branhc (also includes the optimization done in #1348). These were ran on a MacBook Air M1 with 16 GB and opt level 2.

Class Hash Main (ms) Branch (ms) Improvement
0x1b5fbe104c033025dbb7fb37011781cc9344e881b4828cdaa023a80fecafde4 104725 104725 pretty much the same
0x3100defca27214e5f78f25e48a5b05e45899c6834cb4d34f48384c18e14dff7 101950 101891 pretty much the same
0x79666cdb4fc3cbcafbd74f4ea4e2855bf455c5a7c70915f5679325c54032771 111256 111338 pretty much the same
0xa40ecaa08eaef629d433b15f6b017461df8bea9b4e7299eb8ba3632e32b5a5 117813 117941 pretty much the same
0x4ffeed293927cd56686a9038a10026a2d3b9602f789d1f163c1c4ac9a822a82 155381 156205 pretty much the same
0x2269858a40ea0535cb373b0c981c91b907466edf6d65bcaf669760bbee0ae4d 145411 145754 pretty much the same
0x5ff378cb2f16804539ecb92e84f273aafbab57d450530e9fe8e87771705a673 120292 120634 pretty much the same
0x4edde37ca59d9dff8f4ac8945b1c4860b606abd61d74727904ad7494fccdfa9 120392 120935 pretty much the same

Checklist

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

Copy link

github-actions bot commented Aug 8, 2025

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 2.568 ± 0.020 2.542 2.598 1.04 ± 0.01
base dict_insert.cairo (AOT) 2.480 ± 0.024 2.430 2.512 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 2.568 ± 0.021 2.541 2.609 1.03 ± 0.01
head dict_insert.cairo (AOT) 2.484 ± 0.008 2.473 2.499 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 2.262 ± 0.010 2.246 2.278 1.05 ± 0.01
base dict_snapshot.cairo (AOT) 2.151 ± 0.013 2.129 2.168 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 2.270 ± 0.017 2.236 2.303 1.05 ± 0.01
head dict_snapshot.cairo (AOT) 2.163 ± 0.019 2.137 2.194 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 2.630 ± 0.013 2.612 2.651 1.01 ± 0.01
base factorial_2M.cairo (AOT) 2.611 ± 0.018 2.587 2.639 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 2.632 ± 0.020 2.592 2.670 1.01 ± 0.01
head factorial_2M.cairo (AOT) 2.595 ± 0.015 2.574 2.617 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 2.173 ± 0.012 2.159 2.193 1.03 ± 0.01
base fib_2M.cairo (AOT) 2.118 ± 0.012 2.098 2.141 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 2.177 ± 0.015 2.152 2.205 1.02 ± 0.01
head fib_2M.cairo (AOT) 2.131 ± 0.017 2.110 2.169 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 2.354 ± 0.021 2.329 2.378 1.07 ± 0.01
base linear_search.cairo (AOT) 2.207 ± 0.012 2.188 2.223 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 2.349 ± 0.017 2.319 2.382 1.06 ± 0.01
head linear_search.cairo (AOT) 2.213 ± 0.016 2.187 2.241 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 2.459 ± 0.009 2.446 2.474 1.07 ± 0.01
base logistic_map.cairo (AOT) 2.291 ± 0.022 2.250 2.327 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 2.474 ± 0.020 2.448 2.515 1.08 ± 0.01
head logistic_map.cairo (AOT) 2.296 ± 0.019 2.274 2.328 1.00

Copy link

github-actions bot commented Aug 8, 2025

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 10.574 ± 0.082 10.501 10.784 4.24 ± 0.07
cairo-native (embedded AOT) 2.497 ± 0.033 2.437 2.548 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.544 ± 0.040 2.506 2.641 1.02 ± 0.02

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 528.3 ± 3.4 524.1 535.7 1.00
cairo-native (embedded AOT) 2110.0 ± 18.7 2077.4 2138.3 3.99 ± 0.04
cairo-native (embedded JIT using LLVM's ORC Engine) 2258.9 ± 31.4 2222.4 2321.2 4.28 ± 0.07

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.621 ± 0.014 4.609 4.652 1.82 ± 0.01
cairo-native (embedded AOT) 2.539 ± 0.014 2.518 2.562 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.617 ± 0.048 2.546 2.707 1.03 ± 0.02

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 4.559 ± 0.016 4.529 4.586 2.21 ± 0.03
cairo-native (embedded AOT) 2.065 ± 0.027 2.028 2.115 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 2.145 ± 0.029 2.113 2.206 1.04 ± 0.02

Benchmark for program linear_search

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 575.5 ± 5.6 566.1 584.3 1.00
cairo-native (embedded AOT) 2167.7 ± 12.9 2149.8 2193.4 3.77 ± 0.04
cairo-native (embedded JIT using LLVM's ORC Engine) 2319.8 ± 14.5 2297.3 2342.7 4.03 ± 0.05

Benchmark for program logistic_map

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 373.6 ± 2.9 369.7 378.3 1.00
cairo-native (embedded AOT) 2246.4 ± 23.5 2214.6 2292.9 6.01 ± 0.08
cairo-native (embedded JIT using LLVM's ORC Engine) 2469.7 ± 29.6 2417.6 2504.7 6.61 ± 0.09

@codecov-commenter
Copy link

codecov-commenter commented Aug 26, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.26%. Comparing base (76bedd6) to head (bc3dd15).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1353      +/-   ##
==========================================
+ Coverage   76.22%   76.26%   +0.04%     
==========================================
  Files         111      111              
  Lines       26520    26569      +49     
==========================================
+ Hits        20214    20264      +50     
+ Misses       6306     6305       -1     

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

@DiegoCivi
Copy link
Contributor Author

Closing this PR since it showed no improvement in the compilation times of the circuit related contracts

@DiegoCivi DiegoCivi closed this Sep 8, 2025
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