Skip to content

Optimize kv_idx_update: use modify instead of remove+create#282

Open
heifner wants to merge 1 commit intomasterfrom
feature/chainbase-optimizations
Open

Optimize kv_idx_update: use modify instead of remove+create#282
heifner wants to merge 1 commit intomasterfrom
feature/chainbase-optimizations

Conversation

@heifner
Copy link
Copy Markdown
Contributor

@heifner heifner commented Apr 3, 2026

Summary

  • kv_idx_update now uses db.modify() instead of db.remove() + db.create() when a secondary key changes
  • undo_index::post_modify rebalances only the affected AVL tree index, reducing tree operations from 6 to 2 per secondary index update
  • Eliminates a node deallocation/reallocation cycle and one redundant shared_blob allocation (pri_key no longer reassigned)
  • Caches get_deep_mind_logger result in kv_set update path to avoid redundant call

Performance

Estimated ~1-3us savings per secondary index update, scaling with table size (deeper AVL trees = more comparisons per operation). Most impactful for contracts with frequent secondary key modifications (orderbooks, inventories, sorted collections).

undo_index::post_modify handles AVL tree rebalancing when composite
index key fields change. This avoids node deallocation, fresh node
allocation, and reinsertion into all 3 AVL trees per secondary index
update. Added test proving modify correctly rekeys across indices.
Base automatically changed from feature/kv-remove-sso to master April 3, 2026 20:16
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.

1 participant