Skip to content

Conversation

@prestwich
Copy link

πŸ“ 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:

  • Run make lint
  • Run make test
  • Added tests (if applicable)

Copilot AI review requested due to automatic review settings December 19, 2025 14:42
Ok(OrderSimResult::Success(
Arc::new(SimulatedOrder {
order,
order: order.into_owned(),
Copy link
Author

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],
Copy link
Author

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

Copy link
Contributor

Copilot AI left a 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_order and simulate_order_using_fork now accept &[Order] for parent orders and Cow<'_, Order> for the main order
  • NonceKey struct changed from Clone to Copy since 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.

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.

1 participant