Skip to content

Conversation

@GarmashAlex
Copy link
Contributor

The signature builtin contained multiple redundant Felt252 byte round-trips (to_bytes_be followed by from_bytes_be) that provided no normalization benefit since Felt252 values in this codebase are already canonical modulo the Cairo prime, and all consumers (including starknet_crypto::verify and the Cairo PIE serializers) accept or serialize felts directly. This change removes those conversions in add_signature, add_validation_rule, get_additional_data, extend_additional_data, and simplifies air_private_input for r and w computation, reducing allocations and improving clarity without altering behavior or formats.

Copy link
Contributor

@JulianGCalderon JulianGCalderon left a comment

Choose a reason for hiding this comment

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

Looks good @GarmashAlex! Thanks for the contribution.

@gabrielbosio
Copy link
Collaborator

**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 ± σ):     22.629 s ±  0.042 s    [User: 21.752 s, System: 0.874 s]
  Range (min … max):   22.599 s … 22.658 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 1
  Time (mean ± σ):     22.732 s ±  0.017 s    [User: 21.876 s, System: 0.853 s]
  Range (min … max):   22.720 s … 22.744 s    2 runs
 
Summary
  hyper_threading_main threads: 1 ran
    1.00 ± 0.00 times faster than hyper_threading_pr 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 ± σ):     12.121 s ±  0.030 s    [User: 21.729 s, System: 0.872 s]
  Range (min … max):   12.100 s … 12.142 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 2
  Time (mean ± σ):     12.308 s ±  0.046 s    [User: 22.042 s, System: 0.903 s]
  Range (min … max):   12.276 s … 12.341 s    2 runs
 
Summary
  hyper_threading_main threads: 2 ran
    1.02 ± 0.00 times faster than hyper_threading_pr 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 ± σ):      9.805 s ±  0.176 s    [User: 34.449 s, System: 1.058 s]
  Range (min … max):    9.681 s …  9.929 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 4
  Time (mean ± σ):      9.512 s ±  0.111 s    [User: 35.277 s, System: 1.061 s]
  Range (min … max):    9.433 s …  9.590 s    2 runs
 
Summary
  hyper_threading_pr threads: 4 ran
    1.03 ± 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 ± σ):      9.709 s ±  0.021 s    [User: 34.154 s, System: 1.101 s]
  Range (min … max):    9.695 s …  9.724 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 6
  Time (mean ± σ):      9.747 s ±  0.243 s    [User: 35.057 s, System: 1.064 s]
  Range (min … max):    9.575 s …  9.919 s    2 runs
 
Summary
  hyper_threading_main threads: 6 ran
    1.00 ± 0.03 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 ± σ):      9.442 s ±  0.168 s    [User: 34.847 s, System: 1.109 s]
  Range (min … max):    9.323 s …  9.561 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 8
  Time (mean ± σ):      9.630 s ±  0.107 s    [User: 35.179 s, System: 1.095 s]
  Range (min … max):    9.554 s …  9.706 s    2 runs
 
Summary
  hyper_threading_main threads: 8 ran
    1.02 ± 0.02 times faster than hyper_threading_pr 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 ± σ):      9.492 s ±  0.274 s    [User: 35.194 s, System: 1.169 s]
  Range (min … max):    9.299 s …  9.686 s    2 runs
 
Benchmark 2: hyper_threading_pr threads: 16
  Time (mean ± σ):      9.669 s ±  0.230 s    [User: 35.603 s, System: 1.169 s]
  Range (min … max):    9.507 s …  9.832 s    2 runs
 
Summary
  hyper_threading_main threads: 16 ran
    1.02 ± 0.04 times faster than hyper_threading_pr threads: 16

@gabrielbosio
Copy link
Collaborator

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base big_factorial 1.949 ± 0.013 1.932 1.980 1.00
head big_factorial 1.954 ± 0.008 1.942 1.963 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base big_fibonacci 1.877 ± 0.017 1.864 1.918 1.00
head big_fibonacci 1.890 ± 0.010 1.873 1.908 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 6.666 ± 0.120 6.528 6.923 1.00
head blake2s_integration_benchmark 6.705 ± 0.071 6.562 6.825 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 1.989 ± 0.014 1.975 2.020 1.00
head compare_arrays_200000 2.010 ± 0.012 1.993 2.029 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 1.327 ± 0.007 1.319 1.339 1.00
head dict_integration_benchmark 1.341 ± 0.007 1.331 1.358 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base field_arithmetic_get_square_benchmark 1.117 ± 0.010 1.106 1.134 1.00
head field_arithmetic_get_square_benchmark 1.140 ± 0.011 1.125 1.157 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 6.704 ± 0.054 6.659 6.809 1.00
head integration_builtins 6.826 ± 0.056 6.752 6.896 1.02 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 6.802 ± 0.087 6.702 6.979 1.00
head keccak_integration_benchmark 6.861 ± 0.069 6.756 6.946 1.01 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base linear_search 1.980 ± 0.007 1.974 1.999 1.00
head linear_search 1.995 ± 0.009 1.983 2.008 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 1.417 ± 0.005 1.410 1.424 1.00
head math_cmp_and_pow_integration_benchmark 1.433 ± 0.006 1.424 1.443 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 1.372 ± 0.006 1.361 1.381 1.00
head math_integration_benchmark 1.377 ± 0.005 1.365 1.383 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 1.123 ± 0.008 1.116 1.142 1.00
head memory_integration_benchmark 1.132 ± 0.014 1.119 1.161 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 1.446 ± 0.011 1.435 1.470 1.00
head operations_with_data_structures_benchmarks 1.452 ± 0.004 1.445 1.459 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base pedersen 504.3 ± 2.2 502.6 509.9 1.00
head pedersen 505.7 ± 2.1 503.0 509.6 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base poseidon_integration_benchmark 583.7 ± 4.6 578.8 593.6 1.00
head poseidon_integration_benchmark 585.4 ± 2.8 580.1 589.4 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 1.709 ± 0.019 1.689 1.749 1.00
head secp_integration_benchmark 1.711 ± 0.005 1.703 1.721 1.00 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base set_integration_benchmark 646.5 ± 4.1 644.1 658.0 1.03 ± 0.01
head set_integration_benchmark 629.5 ± 1.5 627.3 631.4 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 3.828 ± 0.032 3.794 3.870 1.00
head uint256_integration_benchmark 3.861 ± 0.038 3.825 3.945 1.01 ± 0.01

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