Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions crates/autopilot/src/infra/persistence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,27 +156,31 @@ impl Persistence {
pub fn replace_current_auction_in_db(
&self,
new_auction_id: domain::auction::Id,
new_auction_data: &domain::RawAuctionData,
new_auction_data: &Arc<domain::RawAuctionData>,
) {
self.upload_queue
.send(AuctionUpload {
auction_id: new_auction_id,
auction_data: dto::auction::from_domain(new_auction_data.clone()),
auction_data: dto::auction::from_domain(new_auction_data.as_ref().clone()),
Comment thread
ashleychandy marked this conversation as resolved.
Outdated
})
.expect("upload queue should be alive at all times");
}

/// Spawns a background task that uploads the auction to S3.
pub fn upload_auction_to_s3(&self, id: domain::auction::Id, auction: &domain::RawAuctionData) {
pub fn upload_auction_to_s3(
&self,
id: domain::auction::Id,
auction: &Arc<domain::RawAuctionData>,
) {
if auction.orders.is_empty() {
return;
}
let Some(s3) = self.s3.clone() else {
return;
};
let auction = auction.clone();
let auction = Arc::clone(auction);
tokio::task::spawn(async move {
let auction_dto = dto::auction::from_domain(auction);
let auction_dto = dto::auction::from_domain(auction.as_ref().clone());
match s3.upload(id.to_string(), auction_dto).await {
Ok(key) => tracing::info!(?key, "uploaded auction to s3"),
Err(err) => tracing::warn!(?err, "failed to upload auction to s3"),
Expand Down
6 changes: 3 additions & 3 deletions crates/autopilot/src/run_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,9 @@ impl RunLoop {
Some(domain::Auction {
id,
block: auction.block,
orders: auction.orders,
prices: auction.prices,
surplus_capturing_jit_order_owners: auction.surplus_capturing_jit_order_owners,
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.

})
}

Expand Down
8 changes: 4 additions & 4 deletions crates/autopilot/src/solvable_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub struct SolvableOrdersCache {
type Balances = HashMap<Query, U256>;

struct Inner {
auction: domain::RawAuctionData,
auction: Arc<domain::RawAuctionData>,
solvable_orders: boundary::SolvableOrders,
}

Expand Down Expand Up @@ -186,12 +186,12 @@ impl SolvableOrdersCache {
})
}

pub async fn current_auction(&self) -> Option<domain::RawAuctionData> {
pub async fn current_auction(&self) -> Option<Arc<domain::RawAuctionData>> {
self.cache
.lock()
.await
.as_ref()
.map(|inner| inner.auction.clone())
.map(|inner| Arc::clone(&inner.auction))
}

/// Manually update solvable orders. Usually called by the background
Expand Down Expand Up @@ -358,7 +358,7 @@ impl SolvableOrdersCache {
};

*self.cache.lock().await = Some(Inner {
auction,
auction: Arc::new(auction),
solvable_orders: db_solvable_orders,
});

Expand Down
Loading