-
Notifications
You must be signed in to change notification settings - Fork 394
perf: opt vector operations in tx query path #4424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
perf: opt vector operations in tx query path #4424
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using swap_remove will reduce the readability overhead as it's equivalent to the provided solution.
P.S.:
Leaving this review as a member of the @nolus-protocol dev team.
| ); | ||
|
|
||
| let tx = response.txs.remove(0); | ||
| let tx = response.txs.into_iter().next().expect("tx_search was constrained to a single result"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let tx = response.txs.into_iter().next().expect("tx_search was constrained to a single result"); | |
| let tx = response.txs.swap_remove(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second look, change is unnecessary in the first place because the assertion will fail if there is more than one element.
| Ok(vec![]) | ||
| } else { | ||
| let tx = response.txs.remove(0); | ||
| let tx = response.txs.into_iter().next().expect("tx_search was constrained to a single result"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let tx = response.txs.into_iter().next().expect("tx_search was constrained to a single result"); | |
| let tx = response.txs.swap_remove(0); |
|
|
||
| // In either case, use the first (latest) event found for this sequence | ||
| let (first_event, _, _) = tx_events.remove(0); | ||
| let (first_event, _, _) = tx_events.into_iter().next().expect("tx_events is known to contain at least one entry"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let (first_event, _, _) = tx_events.into_iter().next().expect("tx_events is known to contain at least one entry"); | |
| let (first_event, _, _) = tx_events.swap_remove(0); |
I don't think so. 1.Same O(1) performance as swap_remove |
|
At (1):
Source: At (2): { tx_events }.swap_remove(0)At (3): At (4): |
Closes: #XXX
Description
all 3 remove(0) operations replaced with into_iter().next(). It can avoids the front-shift penalty, O(n) -> O(1)
PR author checklist:
unclog.docs/).mircea-cReviewer checklist:
Files changedin the GitHub PR explorer.