Repository navigation
perf(drive): build batch deletes without copying the pending batch - #5004
Conversation
The batch delete helpers copied every pending grove operation into a fresh batch on each call so GroveDB's delete_operation_for_delete_internal could account for them, which made building k deletes into one batch cost O(k^2) copies. GroveDB reads only the pending operations at the deleted tree's own path (path followed by key), and none when the element is known not to be a tree; the up-tree variant reads one such path per level. The helpers now hand GroveDB exactly those operations. The operations built, their order and their costs are unchanged at every protocol version; tests compare every helper against a verbatim copy of its old implementation, and a test-only counter keeps the full copy out of the per-delete path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (9)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: dashpay/platform/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (10)
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughStateful delete and move paths now pass GroveDB operations selected for each target instead of the full batch. New helpers select operations for individual deletes and delete-up-tree processing. Tests compare results and generated operations with previous implementations and track copied-operation counts. ChangesPending GroveDB delete operations
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~25 minutes Change: Refactor Suggested reviewers: Merge Risk: ⚪ Minimal · up to This change reduces copying when Drive builds batch deletes and moves. Tests cover a wide range of cases and show that the operations built and their costs match the previous behavior. No concrete correctness risk was found, and the change appears ready to merge. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change keeps the existing deletion interfaces and safeguards while reducing the operations copied into each batch. Incorrect filtering could affect tree deletion, but the changed paths preserve operation order and include comparisons with the prior behavior. Validation across supported versions remains worthwhile. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🕓 Queued for automated review — 3rd in line, estimated start in ~25 min (commit fe25e36)
|
GroveDB dashpay/grovedb#995 lets delete_operation_for_delete_internal and delete_operations_for_delete_up_tree_while_empty borrow the pending operations and ask only for those at the deleted tree's own path. Bump GroveDB to dce8252f and pass the batch's grove operations as they are, dropping Drive's copy of GroveDB's selection rules. The operations built and their costs are unchanged. The old-copy comparison tests keep batch_delete, the up-tree chain and batch_remove_raw; batch_move and the path-query helpers changed the same way as batch_delete. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Issue being fixed or feature implemented
Drive's batch delete helpers hand GroveDB the operations already pending in the batch being built, so GroveDB can account for them (a tree whose children the batch already deletes counts as empty, a tree the batch writes into does not). GroveDB took them as a slice (an owned
Vecfor the up-tree builder), while Drive keeps its batch asLowLevelDriveOperations, so every call started withLowLevelDriveOperation::grovedb_operations_batch(drive_operations), which clones every pending grove operation, element values included. Building k deletes into one batch therefore cost O(k^2) copies, while applying the finished batch stays linear.dashpay/grovedb#995 lets GroveDB borrow the pending operations (
PendingOperations): it asks for the ones at the deleted tree's own path, and only when the deleted element is a tree.Measured on a release build (Apple M4, one thread), building the same batch of deletes into one batch:
The before numbers were taken on an idle machine and the after numbers (best of six runs) with other builds running, so the gain is if anything larger.
What was done?
74818cebtodce8252f(perf!: borrow the pending batch when building delete operations grovedb#995 and the fixes merged before it, listed under the in-place section).Cargo.lockchanges only the GroveDB sources.util::grove_operations::pending_grove_operations: the batch's grove operations, ephemeral ones included, borrowed (the operationsgrovedb_operations_batchcopies).batch_delete/batch_delete_with_options,batch_remove_raw,batch_move,batch_delete_items_in_path_query,batch_move_items_in_path_queryandbatch_delete_up_tree_while_emptypass them to GroveDB as they are, on the stateful path only (the estimation path never used the copy). The up-tree helper chainscheck_existing_operationsafter its own batch, as it appended them before.batch_remove_rawfinds the first pending operation on its key by reference, with the same comparisonremove_if_insertmade on the copy, and clones only the element it returns.Before and after, with
noperations already in the batch:GroveDB's default
PendingOperationsanswers by scanning the lent operations, once per tree it deletes, so a tree delete still reads the batch (without copying it). The operations built into the batch, their order and their costs are the same.In-place changes to shipped generations
Every method below has only a
v0, selected byDRIVE_GROVE_METHOD_VERSIONS_V1at every protocol version (1 through 14):batch_deletev0 (batch_delete_v0,batch_delete_with_options_v0)batch_remove_rawv0batch_movev0batch_delete_items_in_path_queryv0batch_move_items_in_path_queryv0batch_delete_up_tree_while_emptyv0Why consensus cannot change:
batch_remove_raw,remove_if_insertused to drop an insert at the removed key from the copy before GroveDB saw it; GroveDB only reads operations under that key (atpathfollowed bykey), never the one at it, so lending it changes nothing. Each edited call site says so.74818ceb..dce8252f, as it reaches Drive:delete_operation_for_delete_internalv0, whichGROVE_V1..GROVE_V3select (protocol versions 1 through 13), reads the same pending operations by the same rule, and the batch apply's own deleted-key set is refactored with the same comparison. FromGROVE_V4(protocol version 14 only, unreleased) a pendingDeleteTreewithSubelementsDeletionBehavior::Skipno longer counts as emptying a tree; Drive never builds one (its tree deletes areDontCheckWithNoCleanup, andDeleteChildrenfor epoch trees), so that path is unreachable from Drive.add_delete_operations_for_delete_up_tree_while_emptynow appends to itsVeconce every level is built; Drive does not call it.GROVE_V4only, and only for elements that carry backward references, which Drive never stores;GROVE_V1..GROVE_V3behaviour and costs unchanged.How Has This Been Tested?
pending_grove_operations/tests.rskeeps verbatim copies of the oldbatch_delete_with_options,batch_delete_up_tree_while_emptyandbatch_remove_raw(each copying the whole batch, now lent to the bumped GroveDB as a slice) and builds the same batch through old and new, comparing the whole operation list (operations and calculated costs) and the result, for:check_existing_operations, stopped by an insert, and unaffected by writes beside the emptied trees;should_not_copy_the_pending_batch_for_each_deletecounts the pending operations copied (a test-only counter ingrovedb_operations_batch): 400 not-a-tree deletes copy none (the old helper copies 79,800), and tree and up-tree deletes copy none.batch_delete's GroveDB call an empty batch, or droppingcheck_existing_operationsfrom the up-tree call, each fails the comparison tests.Debugoutput, costs included).cargo clippy --workspace --all-targets --all-features --locked -- --no-deps -D warnings,cargo test -p drive(all passing),cargo test -p drive-abcilib tests (3,556 passing) and strategy tests withRUST_MIN_STACK=4194304as CI runs them (104 passing),cargo test -p drive-proof-verifier(336 passing) andcargo test -p dash-sdk(recorded proof vectors included, all passing) for the GroveDB bump's verification changes,cargo check -p drive --no-default-features --features verify,cargo check -p wasm-drive-verify --target wasm32-unknown-unknown,cargo fmt --all.Breaking Changes
None. The operations built, their order and their costs are unchanged at every protocol version.
Checklist:
structure.rs, regeneratedgrovedb-structure.json, and checked the structure viewer link posted on this pull requestFor repository code-owners and collaborators only
🤖 Generated with Claude Code
Summary by CodeRabbit