Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the auction metrics to improve performance by removing the OrderFilterCounter and its inefficient checkpoint method. The new approach has filtering functions return removed orders directly, which is a significant improvement. My review focuses on the correctness and performance of the new implementation. I have one suggestion to further optimize a new metrics helper function, which aligns with the PR's performance goals and does not conflict with any established rules.
|
|
||
| async fn get_orders_with_native_prices( | ||
| orders: Vec<Arc<Order>>, | ||
| mut orders: Vec<Arc<Order>>, |
There was a problem hiding this comment.
nit: the let mut later on was useful to pinpoint where the mutability need started
There was a problem hiding this comment.
Hmm, not sure this argument makes sense to me. Shouldn't we by that logic make the orders immutable again afterwards?
Reverted back to the original mut since this is not a hill I want to die on but it fees like there should be a somewhat obvious rule one could follow regarding that.
Description
A surprisingly big amount of time in the auction building process is wasted with metrics.
By far the biggest offender is the function
checkpoint()which figures out which orders got filtered out since the last checkpoint. It does it by cloning the currently alive orders and removing the still alive orders from that map one by one. All the orders that are left over are no longer alive.This regularly incurs an overhead of a couple milliseconds each while the alternative function
checkpoint_by_invalid_orders()(which gets the removed orders passed in) only takes a few microseconds.Additionally constructing the an
OrderFilterCounteralso take ~5ms because it clones the original set of orders and counts them already there.Changes
OrderFilterCounterin favor of function on the metricsThis technically introduces breaking changes but IMO those are well worth it: