wrap RawAuctionData in Arc for efficient sharing#4392
Conversation
There was a problem hiding this comment.
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.
| orders: auction.orders.clone(), | ||
| prices: auction.prices.clone(), | ||
| surplus_capturing_jit_order_owners: auction.surplus_capturing_jit_order_owners.clone(), |
There was a problem hiding this comment.
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.
|
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? |
Sadly, we need to measure this in production, meaning that you can't really provide the benchmarks out of the box. 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. |
Description
Fixes a performance issue where
RawAuctionDatawas fully cloned on everycurrent_auction()call in the run loop. Wrapping it inArcmakes the clone operation a reference counter increment instead of a deep copy of all orders, prices, and metadata.Changes
RawAuctionDatainArcwithin the solvable orders cachecurrent_auction()to returnArc<RawAuctionData>and use cheapArc::clone()&Arc<RawAuctionData>and use.as_ref().clone()when cloning is necessarydomain::Auctionor DTO (once per auction vs. every cache access)