Skip to content

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

Merged
Mirko-von-Leipzig merged 2 commits intomirko-cleanup-mempoolfrom
mirko-dont-clone-txs
Nov 27, 2024
Merged

feat(block-producer): borrow instead of cloning txs#544
Mirko-von-Leipzig merged 2 commits intomirko-cleanup-mempoolfrom
mirko-dont-clone-txs

Conversation

@Mirko-von-Leipzig
Copy link
Copy Markdown
Collaborator

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

@Mirko-von-Leipzig Mirko-von-Leipzig added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Nov 5, 2024
Copy link
Copy Markdown
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
Copy Markdown
Collaborator 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
Copy Markdown
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
Copy Markdown
Collaborator 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
Copy Markdown
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
@Mirko-von-Leipzig Mirko-von-Leipzig deleted the mirko-dont-clone-txs branch November 27, 2024 09:09
Mirko-von-Leipzig added a commit that referenced this pull request Dec 9, 2024
This was previously added in #544 but was mistakenly dropped by a rebase.
Mirko-von-Leipzig added a commit that referenced this pull request Dec 9, 2024
This was previously added in #544 but was mistakenly dropped by a rebase.
Mirko-von-Leipzig added a commit that referenced this pull request Dec 10, 2024
This was previously added in #544 but was mistakenly dropped by a rebase.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants