-
Notifications
You must be signed in to change notification settings - Fork 156
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!: refactor Program
to reduce clone
time
#999
Conversation
651fda1
to
ea75559
Compare
Benchmark Results for unmodified programs 🚀
|
ea75559
to
5bec08b
Compare
No slowdown above uncertainty was detected, so this solution is acceptable in principle.
22% improvement on creation of 100 runners from a single program at virtually no extra cost. |
Program
so less used fields aren't copied on CairoRunner
construction
5bec08b
to
f7e90ef
Compare
Program
so less used fields aren't copied on CairoRunner
constructionProgram
to reduce clone
time
f7e90ef
to
2fc2649
Compare
Codecov Report
@@ Coverage Diff @@
## main #999 +/- ##
==========================================
- Coverage 98.02% 98.01% -0.01%
==========================================
Files 76 76
Lines 31621 31646 +25
==========================================
+ Hits 30997 31019 +22
- Misses 624 627 +3
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
ca78d89
to
4baa387
Compare
Extract most fields (see the code for the details) in `Program` into a new `SharedProgramData` structure, then add a field `shared_program_data: Arc<SharedProgramData>` to `Program`, so cloning doesn't deep copy them. These were selected based on how often the runner needed to access them directly, as the indirection and heap access proved to come with a runtime cost. Frequently accessed fields are still copied because of that. The break comes from hiding some symbols (as they were moved to the new structure), but those shouldn't have been exposed in the first place, so I expect no breakage for real-world programs (cue Hyrum's law).
4baa387
to
aaccaf1
Compare
Extract most fields (see the code for the details) in `Program` into a new `SharedProgramData` structure, then add a field `shared_program_data: Arc<SharedProgramData>` to `Program`, so cloning doesn't deep copy them. These were selected based on how often the runner needed to access them directly, as the indirection and heap access proved to come with a runtime cost. Frequently accessed fields are still copied because of that. The break comes from hiding some symbols (as they were moved to the new structure), but those shouldn't have been exposed in the first place, so I expect no breakage for real-world programs (cue Hyrum's law).
There was a report that
CairoRunner::new
took a significant time (~6%) of the runtime in a program that reuses the sameProgram
structure to execute it many times for short runtimes. This is significant and couldn't be caught before by the regular workflow ofcairo-vm-cli
(it runs a program once, so it can only be caught if awfully slow).This change should help any kind of sequencers, so I think it's worth it.
The fields that were extracted are either used only on initialization or on error paths. The rest are still being copied, as a previous approach of passing
Arc<Program>
instead ofProgram
toCairoRunner::new
led to a big performance hit.The change should non-breaking because it's kept internal to
Program
: there's a newpub(crate)
field that keeps anArc<SharedProgramData>
, so no public function changes. However, we did some oversharing of internal data in previous releases and now it's technically breaking: the fields we moved are no longer visible, and wouldn't be accessible with the same paths anyway.Two other approaches we tried first:
CairoRunner
which broke in an unfixable waycairo-rs-py
:PyO3
can't deal with structs having their lifetime managed by Rust.Arc<Program>
inCairoRunner
: as mentioned, this made execution much slower (10-20%).Checklist
addedupdated