Skip to content

Mempool optimizations#2062

Merged
ImplOfAnImpl merged 1 commit into
masterfrom
mempool_optimizations
May 29, 2026
Merged

Mempool optimizations#2062
ImplOfAnImpl merged 1 commit into
masterfrom
mempool_optimizations

Conversation

@ImplOfAnImpl

@ImplOfAnImpl ImplOfAnImpl commented May 22, 2026

Copy link
Copy Markdown
Contributor
  • Collections in MempoolStore that have tx id as the key were changed from btree-based to hash-based. Note that I decided to use hashbrown's containers directly, instead of using the standard ones (which also use hashbrown under the hood), because the size estimation is more precise in this case.
  • There were a few places where the whole mempool would be traversed when adding a new tx:
    • TxPool::remove_expired_transactions would iterate the entire MempoolStore::txs_by_creation_time even though only the first few txs need to be checked.
    • MempoolStore had methods refresh_ancestors/refresh_descendants, which were called from add_to_descendant_score_index/remove_from_ancestor_score_index/remove_from_descendant_score_index - they would remove all ancestors/descendants from txs_by_ancestor_score or txs_by_descendant_score and reinsert them with the new score. I removed these refresh_ methods, and now txs_by_ancestor_score/txs_by_descendant_score are updated in the places where the score is modified - in update_ancestor_state_for_add/update_ancestor_state_for_drop/update_descendant_state_for_drop.
  • New tx's ancestors were collected multiple times. I added the TxMempoolEntryWithAncestors struct, so that the collected ancestors can be re-used at least during the new entry initialization.

I also updated comments and did some renaming in get_best_tx_ids_by_score_and_ancestry and its helper function collect_selected_ancestors (which is now called collect_nearest_selected_ancestors and is in a separate module). The logic here wasn't changed, it's just that the old comments and naming were misleading.

@ImplOfAnImpl ImplOfAnImpl force-pushed the mempool_optimizations branch from 5bdfc4f to 7a1ed16 Compare May 22, 2026 13:03
@ImplOfAnImpl ImplOfAnImpl marked this pull request as ready for review May 25, 2026 08:06
@ImplOfAnImpl ImplOfAnImpl merged commit 7e23788 into master May 29, 2026
20 checks passed
@ImplOfAnImpl ImplOfAnImpl deleted the mempool_optimizations branch May 29, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants