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: eager resize for ´load_data´ #1117

Merged
merged 2 commits into from
May 5, 2023
Merged

Conversation

Oppen
Copy link
Member

@Oppen Oppen commented May 4, 2023

Some of the overhead during runner/vm initialization (relevant for sequencers that recycle a single program) comes from multiple resizes when calling load_data.
Reversing the iterator ensures the resize happens only once, as the biggest offset will be inserted first.

According to criterion benchmarks, initialization takes 29.5% less time.

NOTE: there seems to be a minimal (<0.02+-0.02) performance hit on runtime, presumably due to zeroing out cells to later overwrite them. While more complex, an option would be to .try_reserve instead and then pushing in forward order. For now, I think the complexity/performance trade off balances quite highly in favor of not adding such code.

Checklist

  • Linked to Github Issue
  • Unit tests added
  • Integration tests added.
  • This change requires new documentation.
    • Documentation has been added/updated.
    • CHANGELOG has been updated.

@Oppen Oppen force-pushed the perf/eager_memory_resize_load_data branch from 2b4eaf4 to afef3b7 Compare May 4, 2023 21:54
@codecov
Copy link

codecov bot commented May 4, 2023

Codecov Report

Merging #1117 (aabef6b) into main (06f4c19) will not change coverage.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1117   +/-   ##
=======================================
  Coverage   98.15%   98.15%           
=======================================
  Files          85       85           
  Lines       34546    34546           
=======================================
  Hits        33909    33909           
  Misses        637      637           
Impacted Files Coverage Δ
src/vm/vm_memory/memory_segments.rs 98.99% <100.00%> (ø)

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

@github-actions
Copy link

github-actions bot commented May 4, 2023

Benchmark Results for unmodified programs 🚀

Command Mean [s] Min [s] Max [s] Relative
base blake2s_integration_benchmark 16.750 ± 0.270 16.572 17.499 1.00 ± 0.02
head blake2s_integration_benchmark 16.728 ± 0.059 16.677 16.852 1.00
Command Mean [s] Min [s] Max [s] Relative
base compare_arrays_200000 5.054 ± 0.036 5.019 5.130 1.00
head compare_arrays_200000 5.084 ± 0.058 5.016 5.150 1.01 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base dict_integration_benchmark 3.180 ± 0.025 3.158 3.233 1.01 ± 0.01
head dict_integration_benchmark 3.151 ± 0.009 3.139 3.163 1.00
Command Mean [s] Min [s] Max [s] Relative
base factorial_multirun 5.354 ± 0.021 5.329 5.389 1.00 ± 0.00
head factorial_multirun 5.339 ± 0.011 5.317 5.358 1.00
Command Mean [s] Min [s] Max [s] Relative
base fibonacci_1000_multirun 4.717 ± 0.011 4.702 4.738 1.00
head fibonacci_1000_multirun 4.753 ± 0.046 4.715 4.874 1.01 ± 0.01
Command Mean [ms] Min [ms] Max [ms] Relative
base field_arithmetic_get_square_benchmark 202.2 ± 2.0 199.9 205.2 1.00
head field_arithmetic_get_square_benchmark 202.9 ± 1.1 201.3 205.5 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base integration_builtins 15.675 ± 0.182 15.541 16.149 1.00 ± 0.02
head integration_builtins 15.671 ± 0.173 15.566 16.152 1.00
Command Mean [s] Min [s] Max [s] Relative
base keccak_integration_benchmark 16.743 ± 0.096 16.642 16.914 1.00 ± 0.01
head keccak_integration_benchmark 16.669 ± 0.105 16.605 16.934 1.00
Command Mean [s] Min [s] Max [s] Relative
base linear_search 5.129 ± 0.079 5.050 5.291 1.00 ± 0.02
head linear_search 5.111 ± 0.077 5.034 5.286 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_cmp_and_pow_integration_benchmark 3.462 ± 0.025 3.430 3.513 1.00 ± 0.01
head math_cmp_and_pow_integration_benchmark 3.447 ± 0.018 3.428 3.489 1.00
Command Mean [s] Min [s] Max [s] Relative
base math_integration_benchmark 3.228 ± 0.013 3.210 3.252 1.00 ± 0.01
head math_integration_benchmark 3.226 ± 0.011 3.211 3.240 1.00
Command Mean [s] Min [s] Max [s] Relative
base memory_integration_benchmark 2.826 ± 0.007 2.816 2.838 1.00 ± 0.01
head memory_integration_benchmark 2.821 ± 0.014 2.809 2.858 1.00
Command Mean [s] Min [s] Max [s] Relative
base operations_with_data_structures_benchmarks 3.193 ± 0.011 3.176 3.212 1.00 ± 0.00
head operations_with_data_structures_benchmarks 3.177 ± 0.005 3.167 3.184 1.00
Command Mean [s] Min [s] Max [s] Relative
base pedersen 1.019 ± 0.003 1.016 1.026 1.00
head pedersen 1.022 ± 0.008 1.016 1.042 1.00 ± 0.01
Command Mean [s] Min [s] Max [s] Relative
base poseidon_integration_benchmark 1.692 ± 0.006 1.684 1.701 1.00 ± 0.00
head poseidon_integration_benchmark 1.685 ± 0.004 1.681 1.693 1.00
Command Mean [s] Min [s] Max [s] Relative
base secp_integration_benchmark 3.892 ± 0.016 3.871 3.920 1.00 ± 0.01
head secp_integration_benchmark 3.877 ± 0.017 3.863 3.916 1.00
Command Mean [s] Min [s] Max [s] Relative
base set_integration_benchmark 2.014 ± 0.007 2.006 2.029 1.00 ± 0.01
head set_integration_benchmark 2.011 ± 0.020 1.997 2.060 1.00
Command Mean [s] Min [s] Max [s] Relative
base uint256_integration_benchmark 10.100 ± 0.054 10.034 10.196 1.00 ± 0.01
head uint256_integration_benchmark 10.051 ± 0.020 10.023 10.081 1.00

@Oppen Oppen enabled auto-merge May 5, 2023 22:27
@Oppen Oppen added this pull request to the merge queue May 5, 2023
Merged via the queue into main with commit e284753 May 5, 2023
30 checks passed
@Oppen Oppen deleted the perf/eager_memory_resize_load_data branch May 5, 2023 22:56
kariy pushed a commit to dojoengine/cairo-rs that referenced this pull request Jun 23, 2023
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

3 participants