Skip to content

TreeDB collections: reuse semantic document IDs in direct buffered updates - #1380

Open
snissn wants to merge 1 commit into
codex/1242-pr3b-semantic-value-diff-fastpathfrom
codex/1242-pr3b-semantic-record-allocation
Open

TreeDB collections: reuse semantic document IDs in direct buffered updates#1380
snissn wants to merge 1 commit into
codex/1242-pr3b-semantic-value-diff-fastpathfrom
codex/1242-pr3b-semantic-record-allocation

Conversation

@snissn

@snissn snissn commented May 5, 2026

Copy link
Copy Markdown
Owner

Summary

This is a small allocation follow-up stacked on #1379.

The direct buffered update path already builds a cloned primary root key for each modified document. Semantic update records were cloning the same document ID again. This reuses the direct primary entry key for the semantic sidecar when the direct plan is available, while keeping the existing clone fallback for non-direct plans.

Scope

  • No semantic behavior change.
  • No publish path change.
  • No root-delta planning change.
  • Direct buffered plans only avoid the redundant document ID clone.

Validation

go test ./TreeDB/collections -count=1
go test -race ./TreeDB/collections \
  -run 'TestIndexedSemanticValueSetDiffFastPathsMatchMultiValueSemantics|TestPR3bSemantic|TestCollection.*SkipsSecondaryRoot' \
  -count=1

Exact direct 5k docs / 50k indexed repeated-ID update canary:

MONGO_GATEWAY_PROFILE_BENCH_UPDATE_DOCUMENTS=5000 \
MONGO_GATEWAY_PROFILE_BENCH_CONCURRENT_WRITERS=4 \
MONGO_GATEWAY_PROFILE_BENCH_BATCH_SIZE=5000 \
MONGO_GATEWAY_PROFILE_BENCH_BUFFERED_INDEXED_WRITE_MAX_DOCUMENTS=100000 \
MONGO_GATEWAY_PROFILE_BENCH_BUFFERED_INDEXED_WRITE_MAX_ROOT_RUNS=0 \
go test ./cmd/mongo_gateway_bench \
  -run '^$' \
  -bench '^BenchmarkDirectCollectionConcurrentUpdateBSONIndexes2CityUpdate$' \
  -benchtime=50000x \
  -benchmem \
  -count=3

Local result summary:

Branch ns/op avg B/op avg allocs/op
#1379 baseline ~4020 ~4658 11
this PR ~3953 ~4548 10

This does not solve the broader allocation gap versus main, but it removes one redundant per-update allocation in the PR3b direct buffered path.

Copilot AI review requested due to automatic review settings May 5, 2026 18:02

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 reduces per-update allocations in TreeDB’s direct buffered UpdateBatch path by reusing the already-cloned primary document ID key when constructing indexed semantic sidecar records, instead of cloning the document ID a second time.

Changes:

  • Extend buildIndexedSemanticUpdateRecords to optionally accept direct buffered primaryEntries and reuse primaryEntries[i].key as the semantic record documentID when available.
  • Wire the direct buffered update plan to pass primaryEntries into semantic record construction; non-direct plans pass nil and keep the existing clone behavior.

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

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