Skip to content

TreeDB collections: pack semantic index deltas per batch - #1383

Open
snissn wants to merge 1 commit into
codex/1242-pr3b-semantic-checkpoint-shallowfrom
codex/1242-pr3b-semantic-delta-arena
Open

TreeDB collections: pack semantic index deltas per batch#1383
snissn wants to merge 1 commit into
codex/1242-pr3b-semantic-checkpoint-shallowfrom
codex/1242-pr3b-semantic-delta-arena

Conversation

@snissn

@snissn snissn commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

  • Pack semantic index-delta records for each update batch into one contiguous slice.
  • Each semantic record keeps a tight subslice of that batch-local delta arena.
  • Avoids allocating a separate []indexedSemanticIndexDelta backing array for every changed document.

Validation

  • go test ./TreeDB/collections -run 'TestPR3bSemantic|TestIndexedSemantic|TestCollection.*SkipsSecondaryRoot|Test.*Rollback|Test.*AutoFlush|TestCollectionIndexedFlush' -count=1
  • go test ./cmd/mongo_gateway_bench -run '^$' -bench '^BenchmarkDirectCollectionConcurrentUpdateBSONIndexes2CityUpdate$' -benchtime=500000x -benchmem -count=1
  • go test ./cmd/mongo_gateway_bench -run '^$' -bench '^BenchmarkDirectCollectionConcurrentUpdateBSONIndexes2CityUpdate$' -benchtime=50000x -benchmem -count=3

Benchmark evidence on the 5k docs / 500k direct indexed repeated-ID update canary, relative to #1382:

#1382 shallow checkpoint: 3881 ns/op, 3691 B/op, 10 allocs/op
this branch:              3843-3860 ns/op, 3716-3736 B/op, 9 allocs/op

The profile still shows appendIndexedSemanticRecordsLocked as the larger remaining semantic-record allocation source. This PR only removes the per-record delta backing arrays; it does not change publish semantics or effective coalescing behavior.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR changes TreeDB’s buffered indexed-update path so semantic index deltas for a batch are packed into one shared contiguous slice instead of allocating a separate delta backing array per changed document. It fits into the recent PR3b semantic staging/allocation work by targeting another hot allocation source in TreeDB/collections.

Changes:

  • Pre-computes the total semantic index-delta count for a batch.
  • Allocates one batch-local []indexedSemanticIndexDelta arena and assigns each record a tight subslice into it.
  • Keeps the existing semantic-record contents and fallback behavior while changing only how the delta slices are backed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread TreeDB/collections/api.go
Comment on lines +9238 to +9242
for _, update := range updates {
if !update.indexStateChanged {
continue
}
for runtimeIdx := range runtimes {
Comment thread TreeDB/collections/api.go
Comment on lines +9249 to +9250
indexDeltas := make([]indexedSemanticIndexDelta, totalIndexDeltas)
indexDeltaPos := 0
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