perf: opt vector operations in tx query path#4424
perf: opt vector operations in tx query path#4424songgaoye wants to merge 2 commits intoinformalsystems:masterfrom
Conversation
There was a problem hiding this comment.
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.
| 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.
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.
| 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.
| 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.