You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To avoid expensive clones, replaced Order with Arc in almost all the code.
Notice that the Arc also enforces immutability, which is something good for the Orders.
This PR wraps Order in Arc<Order> throughout the codebase to avoid expensive clones. The change is well-executed and the benefits are clear:
Performance: Order contains Bundle which has Vec<TransactionSignedEcRecoveredWithBlobs> - each clone previously required deep copying transaction data. With Arc, clones are now just reference count increments (atomic pointer copy).
Immutability: As noted in the PR description, Arc enforces immutability at the type level, which is appropriate since orders shouldn't be modified after creation.
Code Quality Assessment
Strengths:
Consistent pattern applied across all 37 files
Clean use of Arc::clone(&order) instead of order.clone() which makes the intent explicit
Added a proper constructor SimulatedOrder::new() rather than exposing the struct fields directly
Test files updated appropriately
Observations:
SimulatedOrder::new() constructor (crates/rbuilder-primitives/src/lib.rs:1020-1030): Good addition. This encapsulates construction and makes future changes easier.
Pattern consistency: The PR consistently uses Arc::clone(&x) rather than x.clone() which is the recommended Rust idiom for Arc - it makes it clear that only a reference count increment is happening, not a deep clone.
ReplaceableOrderPoolCommand: The changes in orderpool.rs properly use Arc::clone() when forwarding orders to sinks, avoiding unnecessary copies.
Potential Considerations
Memory lifetime: With Arc, orders will remain in memory as long as any reference exists. This is typically fine but worth noting - if there are long-lived caches or data structures holding Arc<Order>, they could prevent memory from being reclaimed. From the code review, this appears to be managed correctly through the existing cleanup mechanisms (head_updated, etc.).
Thread safety: Arc provides thread-safe reference counting. The Order type is already Send + Sync (from deriving standard traits), so this works correctly with the concurrent builder architecture.
No breaking API changes: The changes are internal - external interfaces that take/return Order would need separate consideration, but this PR appears to focus on internal usage.
Minor Notes
The commit message is clear and concise
Lint and test checklist items are marked as passing
Verdict
LGTM - This is a well-structured refactoring that should improve performance by eliminating unnecessary deep clones of order data. The implementation is consistent and follows Rust best practices for shared ownership.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary
To avoid expensive clones, replaced Order with Arc in almost all the code.
Notice that the Arc also enforces immutability, which is something good for the Orders.
✅ I have completed the following steps:
make lintmake test