Skip to content

wrap RawAuctionData in Arc for efficient sharing#4392

Open
ashleychandy wants to merge 3 commits into
cowprotocol:mainfrom
ashleychandy:perf/arc-raw-auction-data
Open

wrap RawAuctionData in Arc for efficient sharing#4392
ashleychandy wants to merge 3 commits into
cowprotocol:mainfrom
ashleychandy:perf/arc-raw-auction-data

Conversation

@ashleychandy
Copy link
Copy Markdown
Contributor

Description

Fixes a performance issue where RawAuctionData was fully cloned on every current_auction() call in the run loop. Wrapping it in Arc makes the clone operation a reference counter increment instead of a deep copy of all orders, prices, and metadata.

Changes

  • Wrap RawAuctionData in Arc within the solvable orders cache
  • Update current_auction() to return Arc<RawAuctionData> and use cheap Arc::clone()
  • Update persistence methods to accept &Arc<RawAuctionData> and use .as_ref().clone() when cloning is necessary
  • Clone auction data only when converting to domain::Auction or DTO (once per auction vs. every cache access)

@ashleychandy ashleychandy requested a review from a team as a code owner May 10, 2026 09:38
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Arc wrapping for RawAuctionData to improve data sharing efficiency within the autopilot service. Feedback suggests avoiding the use of &Arc as a function parameter to reduce unnecessary indirection and simplify the API. Additionally, it was noted that deep clones of auction collections are still being performed in the run loop, and refactoring the domain::Auction struct to use Arc for its internal fields would better achieve the intended performance gains.

Comment thread crates/autopilot/src/infra/persistence/mod.rs Outdated
Comment on lines +305 to +307
orders: auction.orders.clone(),
prices: auction.prices.clone(),
surplus_capturing_jit_order_owners: auction.surplus_capturing_jit_order_owners.clone(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

These lines perform deep clones of the orders, prices, and surplus_capturing_jit_order_owners collections on every auction cycle. While this is necessary because domain::Auction expects owned data, it significantly limits the performance gains of wrapping RawAuctionData in an Arc. To fully achieve the goal of efficient sharing, consider refactoring the domain::Auction struct to use Arc for its collection fields, allowing these to be cheap pointer increments instead of deep copies.

@ashleychandy
Copy link
Copy Markdown
Contributor Author

Hey @MartinquaXD, thanks for the input on the last PR. I’d like to learn the proper way to approach these kinds of optimizations going forward. Could you point me toward the usual steps/process you’d expect here, like how to benchmark it properly and validate that the change is actually meaningful?

@jmg-duarte
Copy link
Copy Markdown
Contributor

Could you point me toward the usual steps/process you’d expect here, like how to benchmark it properly and validate that the change is actually meaningful?

Sadly, we need to measure this in production, meaning that you can't really provide the benchmarks out of the box.
For very obvious improvements, like the iteration reduction, we can merge them confidently that at least things won't get worse.

But in general, we need to measure them before and after, all that not before ensuring they're correct

@ashleychandy
Copy link
Copy Markdown
Contributor Author

But in general, we need to measure them before and after, all that not before ensuring they're correct

Thanks @jmg-duarte , that clears things up. I'll make sure to frame future optimization PRs more carefully and justify claims properly.

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.

2 participants