Restructure logic that assembles the final auction - #4685
Draft
MartinquaXD wants to merge 9 commits into
Draft
Conversation
Contributor
Author
Contributor
|
Claude finished @MartinquaXD's task in 4m 34s —— View job ReviewNice restructure — collapsing the multiple Findings
The Todo
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The current logic to assemble orders tries to be modular which causes a few performance issues. Some issues are:
retainmultiple times - becauseretainpreserves order it can be quite slow if you for example filter out the very first item in the vectorChanges
Restructure the main logic.
Before we even collect the first iterator we already apply as many filters as possible as a few don't require any additional data. This already leaves us with a smaller collection at the start (in number of items, not memory footprint).
While we apply the filters we already store the UID + filter reason in separate vectors for later reporting. We also already collect all the data we need for fetching the remaining data for the next filtering step.
With all the data we collected we can now run ALL async tasks that fetch the final set of data concurrently instead of spreading that around.
One we have the final data we can already
.into_iter().filter_map().collect()and skip ALL.retain()calls.After all is said and done we have a single function call to update metrics, log filtered orders and upload order events to the database.
Besides restructuring the loops I also used alloy's
FbHasherfor maps and sets where the key has a fixed size (Address, OrderUid). Microbenchmarks showed a >10x speed up compared to rust's default hasher. (I imagine in the grand scheme of things this will not do much but the change was dead simple so why not?).Possible improvements that are out of scope of this PR:
retainanymore)How to test
Existing tests were adjusted but more tests are probably needed.