Skip to content

wrap RawAuctionData in Arc#4509

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

wrap RawAuctionData in Arc#4509
ashleychandy wants to merge 7 commits into
cowprotocol:mainfrom
ashleychandy:perf/arc-raw-auction-data

Conversation

@ashleychandy

Copy link
Copy Markdown
Contributor

Description

RawAuctionData was being cloned at multiple callsites, most expensively before the S3 upload background task and before DTO conversion, despite the original value remaining valid and unchanged. This PR wraps RawAuctionData in Arc at the point of creation in SolvableOrdersCache so it can be shared cheaply across the run loop, persistence layer, and solver request serialization without copying heap-allocated order and price data.

Reopened from #4392 (closed by stale bot).

Benchmark results confirm the dominant win: Arc::clone (~3 ns) vs a full DTO clone at 100 orders (~8.8 µs), roughly a 2900x difference on the sharing path. Conversion itself improves by ~48% at 10 orders by eliminating the pre-call clone callers previously needed to retain the original.

Changes

  • Wrap RawAuctionData in Arc inside SolvableOrdersCache::Inner; current_auction() now returns Option<Arc<RawAuctionData>> instead of cloning the struct
  • Introduce CutAuction { id, auction } struct to carry the Arc through cut_auction() -> next_auction() without losing the auction ID
  • Change upload_auction_to_s3 to accept Arc<RawAuctionData> by value so the tokio::spawn closure can take ownership of the reference without cloning the data
  • Update dto::auction::from_domain and dto::order::from_domain to take &RawAuctionData / &Order by reference; use .iter().cloned() where owned values are needed for the DTO
  • Update Quote::from_domain and solver request serialization (dto::solve) to borrow rather than consume
  • Derive Copy on SellTokenSource and BuyTokenDestination (fieldless enums) to remove unnecessary borrows in conversion code
  • Extract log_order_delta as a generic helper; add log_raw_auction_delta for the run loop's raw-data path while preserving the existing log_auction_delta for other callsites

Conversion: old vs new

Size Old New Δ
1 order 256 ns 290 ns -13%
10 orders 2.04 µs 1.06 µs +48%
100 orders 14.46 µs 13.40 µs +7%
500 orders 61.5 µs 60.8 µs ~0% (p=0.15, not significant)

Arc::clone vs dto.clone (100 orders)

Time
dto.clone() 8.8 µs
Arc::clone 3 ns

~2900x difference. If the hot path is convert-once / share-many, wrapping in Arc is the dominant win here.

Raw output
auction_conversion/10_orders/old   time: [1.9683 µs 2.0366 µs 2.1046 µs]
auction_conversion/10_orders/new   time: [1.0604 µs 1.0645 µs 1.0691 µs]
auction_conversion/100_orders/old  time: [14.157 µs 14.455 µs 14.726 µs]
auction_conversion/100_orders/new  time: [13.345 µs 13.401 µs 13.460 µs]
auction_conversion/500_orders/old  time: [60.395 µs 61.479 µs 62.492 µs]
auction_conversion/500_orders/new  time: [60.565 µs 60.806 µs 61.081 µs]
dto_arc_cloning/.../dto_clone      time: [8.7630 µs 8.8028 µs 8.8508 µs]
dto_arc_cloning/.../arc_clone      time: [3.0260 ns 3.0421 ns 3.0591 ns]
order_conversion/.../old           time: [254.33 ns 256.10 ns 257.96 ns]
order_conversion/.../new           time: [289.55 ns 290.51 ns 291.50 ns]

@ashleychandy ashleychandy requested a review from a team as a code owner June 9, 2026 08:35
@ashleychandy ashleychandy changed the title Perf/arc raw auction data wrap RawAuctionData in Arc Jun 9, 2026

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

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.

Code Review

This pull request refactors the autopilot service to pass and store auction data using Arc and references rather than cloning, improving performance. A high-severity issue was identified in run_loop.rs where short-circuiting in a conditional check prevents prev_block from being updated when the auction changes, which could trigger redundant solver runs.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/autopilot/src/run_loop.rs
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