Skip to content

Conversation

@Stavbe
Copy link
Collaborator

@Stavbe Stavbe commented Jul 10, 2025

Up until now, whenever we wanted to keep the trace during execution, we also performed relocation at the end.
In the new adapter flow, we want to enable the option to keep the trace without allocating it.
I’ve set the default value to true to stay consistent with the current behavior.


This change is Reviewable

@Stavbe Stavbe changed the base branch from main to starkware-development July 10, 2025 15:33
@Stavbe Stavbe force-pushed the stav/disable_relocate_trace_with_flag branch from 2d7cfa6 to 29fc7dc Compare July 10, 2025 15:40
@github-actions
Copy link

github-actions bot commented Jul 10, 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 ± σ):     25.705 s ±  0.005 s    [User: 24.943 s, System: 0.760 s]
  Range (min … max):   25.702 s … 25.709 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     25.660 s ±  0.009 s    [User: 24.763 s, System: 0.894 s]
  Range (min … max):   25.654 s … 25.666 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 ± σ):     14.372 s ±  0.067 s    [User: 25.112 s, System: 0.839 s]
  Range (min … max):   14.324 s … 14.419 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     13.928 s ±  0.017 s    [User: 24.845 s, System: 0.895 s]
  Range (min … max):   13.916 s … 13.940 s    2 runs
 
Summary
  hyper_threading_pr threads: 2 ran
    1.03 ± 0.01 times faster than hyper_threading_main 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.874 s ±  0.015 s    [User: 37.611 s, System: 0.975 s]
  Range (min … max):   10.864 s … 10.885 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     10.621 s ±  0.244 s    [User: 36.958 s, System: 1.069 s]
  Range (min … max):   10.448 s … 10.794 s    2 runs
 
Summary
  hyper_threading_pr threads: 4 ran
    1.02 ± 0.02 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.279 s ±  0.123 s    [User: 38.126 s, System: 0.995 s]
  Range (min … max):   10.192 s … 10.366 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):     10.294 s ±  0.361 s    [User: 37.283 s, System: 1.113 s]
  Range (min … max):   10.039 s … 10.549 s    2 runs
 
Summary
  hyper_threading_main threads: 6 ran
    1.00 ± 0.04 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 ± σ):     10.321 s ±  0.047 s    [User: 38.316 s, System: 1.043 s]
  Range (min … max):   10.288 s … 10.354 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):     10.057 s ±  0.050 s    [User: 37.659 s, System: 1.082 s]
  Range (min … max):   10.022 s … 10.092 s    2 runs
 
Summary
  hyper_threading_pr threads: 8 ran
    1.03 ± 0.01 times faster than hyper_threading_main 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.394 s ±  0.209 s    [User: 38.877 s, System: 1.124 s]
  Range (min … max):   10.246 s … 10.541 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):     10.104 s ±  0.172 s    [User: 37.816 s, System: 1.198 s]
  Range (min … max):    9.982 s … 10.226 s    2 runs
 
Summary
  hyper_threading_pr threads: 16 ran
    1.03 ± 0.03 times faster than hyper_threading_main threads: 16


@Stavbe Stavbe force-pushed the stav/disable_relocate_trace_with_flag branch from 29fc7dc to e0eec12 Compare July 10, 2025 15:49
@Stavbe Stavbe requested a review from anatgstarkware July 10, 2025 15:51
@Stavbe Stavbe self-assigned this Jul 10, 2025
@github-actions
Copy link

github-actions bot commented Jul 10, 2025

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.144 ± 0.024 2.127 2.205 1.00 ± 0.02
head big_factorial 2.139 ± 0.025 2.125 2.210 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.072 ± 0.018 2.044 2.101 1.00 ± 0.01
head big_fibonacci 2.070 ± 0.006 2.061 2.079 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 7.618 ± 0.376 7.401 8.638 1.01 ± 0.05
head blake2s_integration_benchmark 7.577 ± 0.056 7.512 7.667 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.210 ± 0.032 2.184 2.275 1.00 ± 0.02
head compare_arrays_200000 2.207 ± 0.013 2.183 2.231 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.438 ± 0.013 1.429 1.469 1.00 ± 0.01
head dict_integration_benchmark 1.437 ± 0.005 1.428 1.448 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.229 ± 0.006 1.221 1.240 1.00
head field_arithmetic_get_square_benchmark 1.235 ± 0.004 1.225 1.239 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 7.606 ± 0.067 7.540 7.715 1.00
head integration_builtins 7.673 ± 0.059 7.611 7.772 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 7.776 ± 0.221 7.611 8.270 1.00
head keccak_integration_benchmark 7.868 ± 0.116 7.761 8.134 1.01 ± 0.03
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.187 ± 0.008 2.175 2.197 1.00
head linear_search 2.194 ± 0.009 2.186 2.215 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.513 ± 0.002 1.510 1.516 1.00
head math_cmp_and_pow_integration_benchmark 1.513 ± 0.005 1.508 1.522 1.00 ± 0.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.472 ± 0.007 1.463 1.486 1.01 ± 0.01
head math_integration_benchmark 1.464 ± 0.006 1.457 1.477 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.216 ± 0.003 1.211 1.220 1.00
head memory_integration_benchmark 1.227 ± 0.009 1.218 1.251 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.546 ± 0.007 1.536 1.560 1.00
head operations_with_data_structures_benchmarks 1.548 ± 0.007 1.537 1.559 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 535.4 ± 1.4 533.6 537.5 1.00 ± 0.00
head pedersen 535.1 ± 1.2 533.9 537.3 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 629.2 ± 3.1 623.3 633.0 1.00
head poseidon_integration_benchmark 631.0 ± 13.5 623.4 668.9 1.00 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.842 ± 0.007 1.837 1.861 1.00 ± 0.00
head secp_integration_benchmark 1.840 ± 0.004 1.831 1.845 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 630.4 ± 6.8 625.8 649.4 1.00 ± 0.01
head set_integration_benchmark 629.5 ± 2.1 627.5 634.5 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.285 ± 0.065 4.210 4.403 1.00
head uint256_integration_benchmark 4.291 ± 0.042 4.262 4.404 1.00 ± 0.02

@codecov
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

❌ Patch coverage is 82.60870% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.63%. Comparing base (4226352) to head (9d2256f).
⚠️ Report is 5 commits behind head on starkware-development.

Files with missing lines Patch % Lines
vm/src/cairo_run.rs 77.77% 4 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                    @@
##           starkware-development    #2133      +/-   ##
=========================================================
- Coverage                  96.63%   96.63%   -0.01%     
=========================================================
  Files                        104      104              
  Lines                      43903    43915      +12     
=========================================================
+ Hits                       42427    42436       +9     
- Misses                      1476     1479       +3     

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

Copy link
Collaborator

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @Stavbe)


vm/src/cairo_run.rs line 31 at r1 (raw file):

    pub trace_enabled: bool,
    pub relocate_mem: bool,
    pub relocate_trace: bool,

Please document

Code quote:

    pub relocate_mem: bool,
    pub relocate_trace: bool,

@Stavbe Stavbe force-pushed the stav/disable_relocate_trace_with_flag branch from e0eec12 to b4a5c88 Compare July 27, 2025 09:28
Copy link
Collaborator Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @anatgstarkware)


vm/src/cairo_run.rs line 31 at r1 (raw file):

Previously, anatgstarkware (anatg) wrote…

Please document

Done.

Copy link
Collaborator

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 4 files reviewed, 4 unresolved discussions (waiting on @Stavbe)


vm/src/cairo_run.rs line 33 at r2 (raw file):

    pub relocate_mem: bool,
    // Disable trace relocation.
    // By default, if trace is enabled, it is also relocated.

It's not clear if you refer to the default below or to the main default args. I would remove this line

Code quote:

By default, if trace is enabled, it is also relocated

vm/src/cairo_run.rs line 59 at r2 (raw file):

            trace_enabled: false,
            relocate_mem: false,
            relocate_trace: true,

This should probably be false, as the rest of the fields here

Code quote:

relocate_trace: true

vm/src/cairo_run.rs line 499 at r2 (raw file):

        let end = cairo_runner.initialize(false).unwrap();
        assert!(cairo_runner.run_until_pc(end, &mut hint_processor).is_ok());
        assert!(cairo_runner.relocate(false, true).is_ok());

Since this test runs with no trace, it makes more sense to put here false

Code quote:

true

cairo-vm-cli/src/main.rs line 195 at r2 (raw file):

        // we need air public input or trace file.
        relocate_trace: trace_enabled
            && (args.trace_file.is_some() || args.air_public_input.is_some()),

I think this main is only used for stone, so maybe these should be true here, WDYT?

Code quote:

        relocate_mem: args.memory_file.is_some() || args.air_public_input.is_some(),
        // If trace not enabled, it is not relevant. Otherwise, we need to relocate the trace only if
        // we need air public input or trace file.
        relocate_trace: trace_enabled
            && (args.trace_file.is_some() || args.air_public_input.is_some()),

@Stavbe Stavbe force-pushed the stav/disable_relocate_trace_with_flag branch from b4a5c88 to d7f56e9 Compare July 29, 2025 09:26
Copy link
Collaborator Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 4 files reviewed, 4 unresolved discussions (waiting on @anatgstarkware)


cairo-vm-cli/src/main.rs line 195 at r2 (raw file):

Previously, anatgstarkware (anatg) wrote…

I think this main is only used for stone, so maybe these should be true here, WDYT?

I think it’s also used to run the VM outside of any prover context, which is why prove_mode is an argument, along with the public and private inputs.
I agree that it definitely won’t be used by Stwo, so I think that the best approach is to set 'reloacte_trace' to match trace_enabled' and by that to turn off Stwo "feature" . As for the original relocate_mem` flag—I think it’s best not to touch it.


vm/src/cairo_run.rs line 33 at r2 (raw file):

Previously, anatgstarkware (anatg) wrote…

It's not clear if you refer to the default below or to the main default args. I would remove this line

Done.


vm/src/cairo_run.rs line 59 at r2 (raw file):

Previously, anatgstarkware (anatg) wrote…

This should probably be false, as the rest of the fields here

Done.


vm/src/cairo_run.rs line 499 at r2 (raw file):

Previously, anatgstarkware (anatg) wrote…

Since this test runs with no trace, it makes more sense to put here false

Done.

@Stavbe Stavbe force-pushed the stav/disable_relocate_trace_with_flag branch 4 times, most recently from 55a5d43 to 4c4ec02 Compare July 29, 2025 13:30
Copy link
Collaborator

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 2 files at r3, 2 of 6 files at r4.
Reviewable status: 3 of 9 files reviewed, 1 unresolved discussion (waiting on @Stavbe)


cairo-vm-cli/src/main.rs line 195 at r2 (raw file):

Previously, Stavbe wrote…

I think it’s also used to run the VM outside of any prover context, which is why prove_mode is an argument, along with the public and private inputs.
I agree that it definitely won’t be used by Stwo, so I think that the best approach is to set 'reloacte_trace' to match trace_enabled' and by that to turn off Stwo "feature" . As for the original relocate_mem` flag—I think it’s best not to touch it.

Didn't the vm relocate the trace also when prove_mode was false?
What do you mean by "original relocate_mem flag"? Was it in stone?


vm/src/cairo_run.rs line 59 at r2 (raw file):

Previously, Stavbe wrote…

Done.

I see you had to change the default in many tests, which means I was wrong. Are these tests only for stone? If so, maybe the default should be the same as in main (i.e., true, as you did before, or trace_enabled), WDYT?
Also, if relocated_mem was added for stwo, then maybe its default should also change.

@Stavbe Stavbe force-pushed the stav/disable_relocate_trace_with_flag branch from 4c4ec02 to bfb6552 Compare July 31, 2025 11:29
Copy link
Collaborator Author

@Stavbe Stavbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 9 files reviewed, 1 unresolved discussion (waiting on @anatgstarkware)


cairo-vm-cli/src/main.rs line 195 at r2 (raw file):

Previously, anatgstarkware (anatg) wrote…

Didn't the vm relocate the trace also when prove_mode was false?
What do you mean by "original relocate_mem flag"? Was it in stone?

  1. The trace was relocated when either args.trace_file.is_some() or args.air_public_input.is_some()
    air_public_input requires proof_mode = true
    trace_file does not require it.
    So in theory the trace could be relocated even when proof_mode = false but I don't see why anyone would want that.

  2. Yes


vm/src/cairo_run.rs line 59 at r2 (raw file):

Previously, anatgstarkware (anatg) wrote…

I see you had to change the default in many tests, which means I was wrong. Are these tests only for stone? If so, maybe the default should be the same as in main (i.e., true, as you did before, or trace_enabled), WDYT?
Also, if relocated_mem was added for stwo, then maybe its default should also change.

These tests are old, and they run the VM with the Stone configuration—so yes.
I think the best approach is to align it with trace_enabled, but you need to fix a value in the default configuration so it is not really an option. I changed it back to true so it won't affect the current VM expected behavior.

Relocate mem was not added for stwo

Copy link
Collaborator

@anatgstarkware anatgstarkware left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 4 files at r1, 1 of 2 files at r3, 2 of 7 files at r5, all commit messages.
Reviewable status: 4 of 9 files reviewed, all discussions resolved (waiting on @Stavbe)


cairo-vm-cli/src/main.rs line 195 at r2 (raw file):

Previously, Stavbe wrote…
  1. The trace was relocated when either args.trace_file.is_some() or args.air_public_input.is_some()
    air_public_input requires proof_mode = true
    trace_file does not require it.
    So in theory the trace could be relocated even when proof_mode = false but I don't see why anyone would want that.

  2. Yes

thanks

@anatgstarkware
Copy link
Collaborator

vm/src/cairo_run.rs line 59 at r2 (raw file):

Previously, Stavbe wrote…

These tests are old, and they run the VM with the Stone configuration—so yes.
I think the best approach is to align it with trace_enabled, but you need to fix a value in the default configuration so it is not really an option. I changed it back to true so it won't affect the current VM expected behavior.

Relocate mem was not added for stwo

Can you please document why it was set to true?

@Stavbe Stavbe force-pushed the stav/disable_relocate_trace_with_flag branch from bfb6552 to 9d2256f Compare July 31, 2025 12:31
@Stavbe Stavbe merged commit 1a224f8 into starkware-development Jul 31, 2025
21 of 23 checks passed
@Stavbe Stavbe deleted the stav/disable_relocate_trace_with_flag branch July 31, 2025 12:32
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.

3 participants