Skip to content

Implement libfunc profiling #1253

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

Merged
merged 1 commit into from
Jun 17, 2025
Merged

Conversation

JulianGCalderon
Copy link
Contributor

@JulianGCalderon JulianGCalderon commented Jun 13, 2025

Implementation of a libfunc profiler.

This PR is a squash of the whole #946 PR. We cannot merge the original PR directly as it has unsigned commits.

There should be no difference between this PR and the original one. You can compare both branches here.

Description

For each executed libfunc, generates:

  • Number of samples.
  • Total number of ticks.
  • Average number of ticks.
  • Standard deviation.
  • Quartiles (0%, 25%, 50%, 75%, 100%).
  • Also implements an outlier detection system to filter out operating system noise.

Note: The x86_64 architecture handles context switches between cores correctly, but in aarch64 this is impossible. Results may not be reliable in aarch64.

Output Example:

[2]
    Total Samples:          281
    Total Execution Time:   111
    Average Execution Time: 0.39501779359430605
    Standard Deviation:     0.23897873633819258
    Quartiles:              [0, 0, 0, 1, 1]

Where [2] refers to the libfunc id.

This commit is a squash of the whole #946 PR
(#946)
@JulianGCalderon JulianGCalderon changed the title Implement libfunc profiling (squash) Implement libfunc profiling Jun 13, 2025
Copy link

Benchmark results Main vs HEAD.

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_insert.cairo (JIT) 5.184 ± 0.065 5.099 5.286 1.00
base dict_insert.cairo (AOT) 5.397 ± 0.187 5.186 5.804 1.04 ± 0.04

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_insert.cairo (JIT) 5.120 ± 0.037 5.074 5.183 1.02 ± 0.01
head dict_insert.cairo (AOT) 5.032 ± 0.064 4.922 5.129 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base dict_snapshot.cairo (JIT) 5.514 ± 0.104 5.377 5.670 1.07 ± 0.05
base dict_snapshot.cairo (AOT) 5.172 ± 0.232 4.964 5.622 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head dict_snapshot.cairo (JIT) 5.037 ± 0.028 5.001 5.085 1.02 ± 0.01
head dict_snapshot.cairo (AOT) 4.919 ± 0.041 4.853 4.968 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base factorial_2M.cairo (JIT) 5.512 ± 0.046 5.456 5.583 1.02 ± 0.01
base factorial_2M.cairo (AOT) 5.413 ± 0.035 5.354 5.482 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head factorial_2M.cairo (JIT) 5.383 ± 0.032 5.316 5.414 1.00 ± 0.01
head factorial_2M.cairo (AOT) 5.362 ± 0.053 5.310 5.496 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base fib_2M.cairo (JIT) 4.945 ± 0.033 4.892 4.994 1.01 ± 0.01
base fib_2M.cairo (AOT) 4.882 ± 0.026 4.849 4.917 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head fib_2M.cairo (JIT) 4.929 ± 0.021 4.913 4.985 1.01 ± 0.01
head fib_2M.cairo (AOT) 4.875 ± 0.022 4.826 4.905 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base linear_search.cairo (JIT) 5.177 ± 0.110 5.088 5.447 1.02 ± 0.02
base linear_search.cairo (AOT) 5.088 ± 0.039 5.007 5.132 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head linear_search.cairo (JIT) 5.107 ± 0.034 5.035 5.136 1.02 ± 0.01
head linear_search.cairo (AOT) 4.987 ± 0.050 4.900 5.051 1.00

Base

Command Mean [s] Min [s] Max [s] Relative
base logistic_map.cairo (JIT) 5.379 ± 0.073 5.262 5.532 1.03 ± 0.02
base logistic_map.cairo (AOT) 5.242 ± 0.093 5.115 5.426 1.00

Head

Command Mean [s] Min [s] Max [s] Relative
head logistic_map.cairo (JIT) 5.209 ± 0.034 5.154 5.266 1.03 ± 0.01
head logistic_map.cairo (AOT) 5.055 ± 0.049 5.002 5.168 1.00

Copy link

Benchmarking results

Benchmark for program dict_insert

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 11.428 ± 0.089 11.360 11.640 2.27 ± 0.02
cairo-native (embedded AOT) 5.046 ± 0.040 4.979 5.088 1.00 ± 0.01
cairo-native (embedded JIT using LLVM's ORC Engine) 5.038 ± 0.032 4.997 5.088 1.00

Benchmark for program dict_snapshot

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 791.9 ± 5.7 783.3 802.9 1.00
cairo-native (embedded AOT) 4823.0 ± 26.7 4781.9 4864.6 6.09 ± 0.06
cairo-native (embedded JIT using LLVM's ORC Engine) 4989.4 ± 25.0 4956.4 5032.3 6.30 ± 0.06

Benchmark for program factorial_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 5.248 ± 0.032 5.208 5.302 1.00 ± 0.01
cairo-native (embedded AOT) 5.235 ± 0.035 5.187 5.289 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 5.311 ± 0.039 5.231 5.364 1.01 ± 0.01

Benchmark for program fib_2M

Open benchmarks
Command Mean [s] Min [s] Max [s] Relative
Cairo-vm (Rust, Cairo 1) 5.052 ± 0.041 5.004 5.132 1.06 ± 0.01
cairo-native (embedded AOT) 4.783 ± 0.029 4.734 4.823 1.00
cairo-native (embedded JIT using LLVM's ORC Engine) 4.816 ± 0.036 4.753 4.856 1.01 ± 0.01

Benchmark for program linear_search

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 820.3 ± 8.6 809.9 835.0 1.00
cairo-native (embedded AOT) 4883.2 ± 20.2 4856.6 4919.4 5.95 ± 0.07
cairo-native (embedded JIT using LLVM's ORC Engine) 5034.6 ± 58.3 4966.4 5131.6 6.14 ± 0.10

Benchmark for program logistic_map

Open benchmarks
Command Mean [ms] Min [ms] Max [ms] Relative
Cairo-vm (Rust, Cairo 1) 537.9 ± 8.1 530.6 558.1 1.00
cairo-native (embedded AOT) 4973.0 ± 64.6 4889.7 5083.4 9.25 ± 0.18
cairo-native (embedded JIT using LLVM's ORC Engine) 5142.0 ± 38.3 5100.6 5204.8 9.56 ± 0.16

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 85.04673% with 48 lines in your changes missing coverage. Please review.

Please upload report for BASE (main@b92123c). Learn more about missing BASE report.

Files with missing lines Patch % Lines
src/libfuncs/starknet.rs 27.27% 32 Missing ⚠️
src/libfuncs/bounded_int.rs 52.94% 8 Missing ⚠️
src/libfuncs/cast.rs 72.72% 3 Missing ⚠️
src/libfuncs/coupon.rs 0.00% 2 Missing ⚠️
src/libfuncs/enum.rs 66.66% 2 Missing ⚠️
src/libfuncs/bytes31.rs 75.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1253   +/-   ##
=======================================
  Coverage        ?   80.21%           
=======================================
  Files           ?      112           
  Lines           ?    29880           
  Branches        ?        0           
=======================================
  Hits            ?    23967           
  Misses          ?     5913           
  Partials        ?        0           

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

@gabrielbosio gabrielbosio added this pull request to the merge queue Jun 17, 2025
Merged via the queue into main with commit 26f1f91 Jun 17, 2025
30 checks passed
@gabrielbosio gabrielbosio deleted the add-libfunc-profiling-squash branch June 17, 2025 14:42
@JulianGCalderon JulianGCalderon mentioned this pull request Jun 17, 2025
5 tasks
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.

4 participants