Skip to content
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

feat(block-producer): borrow instead of cloning txs #544

Merged
merged 2 commits into from
Nov 27, 2024

Conversation

Mirko-von-Leipzig
Copy link
Contributor

Blocked by PR #543.

Removes the unnecessary deep cloning of transaction data by utilising Borrow. The TransactionBatch::new implementation can probably be improved to reduce the amount of iteration occurring, but I'm delaying that until the dust settles on the mempool implementation.

Closes #531

Copy link
Contributor

@polydez polydez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that this PR introduces even more cloning than before, doesn't it? I found 3 cloning of transaction vector here.

@Mirko-von-Leipzig
Copy link
Contributor Author

It seems that this PR introduces even more cloning than before, doesn't it? I found 3 cloning of transaction vector here.

Sort of. We have the following signature now:

txs: impl IntoIterator<Item = Borrow<ProvenTransaction>> + Clone

and txs gets cloned a bunch. However this gets passed in as an iterator:

txs.iter().map(AuthenticatedTransaction::raw_proven_transaction),

so the clones are clones of the iterator. This is a change from before where we cloned the inner transaction data:

txs.iter().map(AuthenticatedTransaction::raw_proven_transaction).cloned().collect()

I'm 95% confident this works how I expect it to. If there is a better/simpler way to express this borrow + reusable iterator bound then that would be perfect.

@polydez
Copy link
Contributor

polydez commented Nov 15, 2024

@Mirko-von-Leipzig this makes sense, thank you! The confusing thing here is that we clone IntoIterator which can be not only iterator itself, but vector as well. I've made my proposal how we can make this simpler and clearer, please take a look: #550

@Mirko-von-Leipzig
Copy link
Contributor Author

@Mirko-von-Leipzig this makes sense, thank you! The confusing thing here is that we clone IntoIterator which can be not only iterator itself, but vector as well. I've made my proposal how we can make this simpler and clearer, please take a look: #550

Agreed; and that is indeed much clearer. I was searching for a clone + iterator combo but missed the fact that you can specify the underlying iterator within IntoIterator.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you!

@Mirko-von-Leipzig Mirko-von-Leipzig merged commit 1a35a9e into mirko-cleanup-mempool Nov 27, 2024
8 checks passed
@Mirko-von-Leipzig Mirko-von-Leipzig deleted the mirko-dont-clone-txs branch November 27, 2024 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants