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

perf: reference management optimizations #1214

Merged
merged 8 commits into from
Jun 15, 2023
Merged

perf: reference management optimizations #1214

merged 8 commits into from
Jun 15, 2023

Conversation

Oppen
Copy link
Member

@Oppen Oppen commented Jun 7, 2023

  • Store the reference list rather than the manager structure
  • Process the reference list only on Program creation rather than in each call to run_for_steps
  • Use a Vec<_> rather than a HashMap<_, _> since the instance is dense
  • Keep this data in the SharedProgramData structure instead of copying it each time
  • Improve the accuracy of the benchmarks

Benchmarks

build runner            time:   [773.76 ns 774.50 ns 775.47 ns]                          
                        change: [-93.906% -93.895% -93.885%] (p = 0.00 < 0.05)
initialize              time:   [20.632 µs 20.649 µs 20.672 µs]                        
                        change: [-16.707% -15.351% -14.383%] (p = 0.00 < 0.05)
parse program           time:   [9.2019 ms 9.2176 ms 9.2341 ms]                          
                        change: [+0.1218% +0.2751% +0.4491%] (p = 0.00 < 0.05)

@github-actions
Copy link

github-actions bot commented Jun 7, 2023

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base factorial_multirun 3.622 ± 0.058 3.575 3.730 1.00
head factorial_multirun 3.689 ± 0.031 3.649 3.734 1.02 ± 0.02
Command Mean [s] Min [s] Max [s] Relative
base fibonacci_1000_multirun 3.094 ± 0.046 3.051 3.211 1.00
head fibonacci_1000_multirun 3.138 ± 0.030 3.112 3.199 1.01 ± 0.02

@unbalancedparentheses
Copy link
Member

image

@Oppen Oppen changed the title wip perf: refence management optimizations Jun 10, 2023
@Oppen Oppen marked this pull request as ready for review June 10, 2023 05:15
@Oppen Oppen changed the title perf: refence management optimizations perf: reference management optimizations Jun 10, 2023
@github-actions
Copy link

github-actions bot commented Jun 14, 2023

Benchmark Results for modified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
head blake2s_integration_benchmark 13.242 ± 0.099 13.141 13.417 1.00
Command Mean [s] Min [s] Max [s] Relative
head compare_arrays_200000 4.600 ± 0.042 4.552 4.656 1.00
Command Mean [s] Min [s] Max [s] Relative
head dict_integration_benchmark 3.047 ± 0.020 3.025 3.090 1.00
Command Mean [ms] Min [ms] Max [ms] Relative
head field_arithmetic_get_square_benchmark 197.0 ± 14.6 186.9 234.0 1.00
Command Mean [s] Min [s] Max [s] Relative
head integration_builtins 11.686 ± 0.149 11.512 11.973 1.00
Command Mean [s] Min [s] Max [s] Relative
head keccak_integration_benchmark 13.550 ± 0.635 13.227 15.326 1.00
Command Mean [s] Min [s] Max [s] Relative
head linear_search 4.598 ± 0.131 4.530 4.963 1.00
Command Mean [s] Min [s] Max [s] Relative
head math_cmp_and_pow_integration_benchmark 3.262 ± 0.034 3.241 3.356 1.00
Command Mean [s] Min [s] Max [s] Relative
head math_integration_benchmark 3.009 ± 0.026 2.983 3.076 1.00
Command Mean [s] Min [s] Max [s] Relative
head memory_integration_benchmark 2.631 ± 0.022 2.612 2.692 1.00
Command Mean [s] Min [s] Max [s] Relative
head operations_with_data_structures_benchmarks 2.986 ± 0.008 2.974 3.002 1.00
Command Mean [s] Min [s] Max [s] Relative
head pedersen 1.042 ± 0.005 1.035 1.053 1.00
Command Mean [s] Min [s] Max [s] Relative
head poseidon_integration_benchmark 1.868 ± 0.012 1.853 1.889 1.00
Command Mean [s] Min [s] Max [s] Relative
head secp_integration_benchmark 3.562 ± 0.023 3.540 3.621 1.00
Command Mean [s] Min [s] Max [s] Relative
head set_integration_benchmark 2.005 ± 0.008 1.990 2.016 1.00
Command Mean [s] Min [s] Max [s] Relative
head uint256_integration_benchmark 8.404 ± 0.032 8.374 8.482 1.00

pefontana and others added 2 commits June 14, 2023 16:19
- Store directly the reference list rather than the whole
  `ReferenceManager` structures
- Only process them once, when creating the `Program`
- Move them to the `SharedProgramData` member
- Convert to `Vec<HintReference>` and adapt the methods using it
@Oppen Oppen enabled auto-merge June 15, 2023 15:07
@codecov
Copy link

codecov bot commented Jun 15, 2023

Codecov Report

Merging #1214 (51a72b4) into main (4221723) will decrease coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #1214      +/-   ##
==========================================
- Coverage   97.61%   97.57%   -0.04%     
==========================================
  Files          88       88              
  Lines       36112    36110       -2     
==========================================
- Hits        35251    35235      -16     
- Misses        861      875      +14     
Impacted Files Coverage Δ
...processor/cairo_1_hint_processor/hint_processor.rs 85.29% <100.00%> (ø)
vm/src/hint_processor/hint_processor_definition.rs 79.10% <100.00%> (-20.90%) ⬇️
vm/src/serde/deserialize_program.rs 96.75% <100.00%> (ø)
vm/src/types/program.rs 99.47% <100.00%> (+0.01%) ⬆️
vm/src/utils.rs 99.49% <100.00%> (ø)
vm/src/vm/runners/cairo_runner.rs 98.01% <100.00%> (-0.01%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Oppen Oppen added this pull request to the merge queue Jun 15, 2023
Merged via the queue into main with commit dbcf4c4 Jun 15, 2023
31 checks passed
@Oppen Oppen deleted the perf/create_runner branch June 15, 2023 15:49
kariy pushed a commit to dojoengine/cairo-rs that referenced this pull request Jun 23, 2023
* wip

* test passing

* more accurate bench

* fix

* perf: optimizations for reference management

- Store directly the reference list rather than the whole
  `ReferenceManager` structures
- Only process them once, when creating the `Program`
- Move them to the `SharedProgramData` member
- Convert to `Vec<HintReference>` and adapt the methods using it

---------

Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com>
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.

None yet

4 participants