-
Notifications
You must be signed in to change notification settings - Fork 178
refactor: reduce allocations in the sim task #842
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
base: develop
Are you sure you want to change the base?
Conversation
| Ok(OrderSimResult::Success( | ||
| Arc::new(SimulatedOrder { | ||
| order, | ||
| order: order.into_owned(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using the Cow allows us to defer the clone to here. This means the clone is eliminated in the (presumably common) case that simulation fails
| pub fn simulate_order_using_fork<Tracer: SimulationTracer>( | ||
| parent_orders: Vec<Order>, | ||
| order: Order, | ||
| parent_orders: &[Order], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
using the reference allows us to not clone the parents, saving a potentially very large allocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR refactors the simulator task to reduce unnecessary cloning and defer allocations for better performance. The changes are primarily focused on passing references instead of owned values and using Cow<'_, Order> to defer cloning until the value needs to be owned.
Key changes:
- Function signatures for
simulate_orderandsimulate_order_using_forknow accept&[Order]for parent orders andCow<'_, Order>for the main order NonceKeystruct changed fromClonetoCopysince it only contains copy types- Removed unnecessary
.clone()calls throughout the codebase
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| simulation_job.rs | Updated comment about tokio::select fairness with documentation link |
| sim_worker.rs | Changed to pass references to parent orders and wrap owned order in Cow::Owned |
| sim.rs | Core refactoring: changed function signatures to accept references, added Cow for deferred cloning, removed unnecessary clones, added tracing instrumentation, and changed NonceKey to Copy |
π‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
π Summary
Reduce cloning in the simulator task. This minimizes and defers new allocations. It is both code cleanup and perf. There are no logic changes.
β I have completed the following steps:
make lintmake test