Skip to content
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

Remove unsafe impl of Add<usize> for &'a Relocatable #1718

Merged
merged 7 commits into from
Apr 17, 2024
Merged

Conversation

fmoletta
Copy link
Contributor

@fmoletta fmoletta commented Apr 16, 2024

The impl of Add<usize> for Relocatable should be used instead, which uses checked_add and handles potential overflows
Closes #1696

@fmoletta fmoletta marked this pull request as ready for review April 16, 2024 16:21
Copy link

github-actions bot commented Apr 16, 2024

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 2.290 ± 0.017 2.270 2.317 1.20 ± 0.03
head big_factorial 1.911 ± 0.039 1.887 1.991 1.00
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 2.301 ± 0.033 2.268 2.367 1.23 ± 0.05
head big_fibonacci 1.877 ± 0.070 1.834 2.064 1.00
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 8.664 ± 0.261 8.341 9.187 1.32 ± 0.05
head blake2s_integration_benchmark 6.541 ± 0.105 6.402 6.721 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 2.351 ± 0.020 2.317 2.390 1.23 ± 0.01
head compare_arrays_200000 1.913 ± 0.013 1.890 1.933 1.00
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.470 ± 0.007 1.460 1.482 1.12 ± 0.02
head dict_integration_benchmark 1.309 ± 0.019 1.298 1.363 1.00
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.413 ± 0.020 1.399 1.465 1.19 ± 0.05
head field_arithmetic_get_square_benchmark 1.186 ± 0.043 1.153 1.289 1.00
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 8.617 ± 0.413 8.341 9.705 1.32 ± 0.06
head integration_builtins 6.532 ± 0.067 6.456 6.652 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 8.819 ± 0.198 8.611 9.119 1.30 ± 0.06
head keccak_integration_benchmark 6.805 ± 0.247 6.661 7.488 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 2.375 ± 0.024 2.353 2.438 1.22 ± 0.01
head linear_search 1.946 ± 0.011 1.934 1.974 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.856 ± 0.040 1.827 1.964 1.10 ± 0.03
head math_cmp_and_pow_integration_benchmark 1.682 ± 0.025 1.659 1.748 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.631 ± 0.026 1.601 1.692 1.11 ± 0.02
head math_integration_benchmark 1.466 ± 0.022 1.442 1.504 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.289 ± 0.014 1.271 1.306 1.13 ± 0.03
head memory_integration_benchmark 1.137 ± 0.025 1.117 1.203 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.936 ± 0.011 1.924 1.959 1.09 ± 0.02
head operations_with_data_structures_benchmarks 1.783 ± 0.028 1.765 1.847 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 558.6 ± 7.8 554.0 580.6 1.09 ± 0.03
head pedersen 513.4 ± 10.6 505.7 541.3 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 997.5 ± 2.6 992.3 1000.3 1.04 ± 0.00
head poseidon_integration_benchmark 958.1 ± 2.8 954.7 964.5 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.951 ± 0.013 1.939 1.976 1.12 ± 0.01
head secp_integration_benchmark 1.737 ± 0.014 1.720 1.769 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 750.3 ± 2.8 746.5 756.3 1.09 ± 0.01
head set_integration_benchmark 685.4 ± 2.0 683.0 688.3 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 4.725 ± 0.065 4.635 4.827 1.22 ± 0.06
head uint256_integration_benchmark 3.881 ± 0.167 3.775 4.284 1.00

@Oppen
Copy link
Contributor

Oppen commented Apr 16, 2024

The performance change seems quite odd.

@Oppen
Copy link
Contributor

Oppen commented Apr 16, 2024

I think the unwrap_or_default calls in the relocation functions becomes a silent failure. Maybe they should bubble up an error instead.

Copy link

codecov bot commented Apr 16, 2024

Codecov Report

Attention: Patch coverage is 96.92308% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 94.91%. Comparing base (b05b541) to head (838c36c).

Files Patch % Lines
vm/src/vm/vm_memory/memory.rs 96.36% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1718   +/-   ##
=======================================
  Coverage   94.91%   94.91%           
=======================================
  Files          98       98           
  Lines       38166    38170    +4     
=======================================
+ Hits        36224    36228    +4     
  Misses       1942     1942           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fmoletta fmoletta enabled auto-merge April 17, 2024 18:30
Copy link

**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 ± σ):     29.362 s ±  0.157 s    [User: 28.660 s, System: 0.700 s]
  Range (min … max):   29.251 s … 29.473 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     23.764 s ±  0.044 s    [User: 23.079 s, System: 0.684 s]
  Range (min … max):   23.733 s … 23.795 s    2 runs
 
Summary
  'hyper_threading_pr threads: 1' ran
    1.24 ± 0.01 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 ± σ):     15.699 s ±  0.018 s    [User: 28.855 s, System: 0.726 s]
  Range (min … max):   15.686 s … 15.712 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     12.449 s ±  0.046 s    [User: 23.209 s, System: 0.760 s]
  Range (min … max):   12.416 s … 12.482 s    2 runs
 
Summary
  'hyper_threading_pr threads: 2' ran
    1.26 ± 0.00 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 ± σ):     11.471 s ±  0.260 s    [User: 40.966 s, System: 0.962 s]
  Range (min … max):   11.287 s … 11.655 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):     10.140 s ±  0.086 s    [User: 34.536 s, System: 0.879 s]
  Range (min … max):   10.079 s … 10.201 s    2 runs
 
Summary
  'hyper_threading_pr threads: 4' ran
    1.13 ± 0.03 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 ± σ):     11.110 s ±  0.038 s    [User: 40.979 s, System: 0.857 s]
  Range (min … max):   11.083 s … 11.137 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):      9.795 s ±  0.042 s    [User: 34.804 s, System: 0.965 s]
  Range (min … max):    9.765 s …  9.824 s    2 runs
 
Summary
  'hyper_threading_pr threads: 6' ran
    1.13 ± 0.01 times faster than 'hyper_threading_main 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 ± σ):     11.057 s ±  0.081 s    [User: 41.365 s, System: 0.985 s]
  Range (min … max):   11.000 s … 11.114 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):      9.496 s ±  0.055 s    [User: 35.264 s, System: 0.961 s]
  Range (min … max):    9.457 s …  9.535 s    2 runs
 
Summary
  'hyper_threading_pr threads: 8' ran
    1.16 ± 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 ± σ):     11.126 s ±  0.055 s    [User: 41.713 s, System: 1.050 s]
  Range (min … max):   11.087 s … 11.165 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):      9.756 s ±  0.083 s    [User: 35.135 s, System: 1.074 s]
  Range (min … max):    9.698 s …  9.815 s    2 runs
 
Summary
  'hyper_threading_pr threads: 16' ran
    1.14 ± 0.01 times faster than 'hyper_threading_main threads: 16'


@fmoletta fmoletta added this pull request to the merge queue Apr 17, 2024
Merged via the queue into main with commit 4b17118 Apr 17, 2024
71 checks passed
@fmoletta fmoletta deleted the remove-unsafe-impl branch April 17, 2024 19:35
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