Skip to content

merge chunks during attach/detach edits#27386

Open
daesunp wants to merge 4 commits into
microsoft:mainfrom
daesunp:merge-attach-detach-edit-chunks
Open

merge chunks during attach/detach edits#27386
daesunp wants to merge 4 commits into
microsoft:mainfrom
daesunp:merge-attach-detach-edit-chunks

Conversation

@daesunp
Copy link
Copy Markdown
Contributor

@daesunp daesunp commented May 26, 2026

Description

Follow-up PR to #27153. Adds coalesceAroundSplice, the inverse of splitFieldAtIndex: merges adjacent same-shape UniformChunks along the seams a splice could have created, so repeated mid-field attach/detach operations don't leave the field permanently fragmented.

splitFieldAtIndex (from #27153) lets attach/detach land in the middle of a multi-node UniformChunk by splitting the chunk. Without a corresponding merge, every mid-chunk edit fragments the field — repeated same-shape inserts would produce an ever-growing run of small adjacent chunks. The uniformChunkNodeCountDynamicTargetMax policy field added in #27153 explicitly anticipated this work; this PR provides the merge logic it was waiting for.

Copilot AI review requested due to automatic review settings May 26, 2026 17:18
@daesunp daesunp requested a review from a team as a code owner May 26, 2026 17:18
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 26, 2026

Hi! Thank you for opening this PR. Want me to review it?

Based on the diff (433 lines, 4 files), I've queued these reviewers:

  • Correctness — logic errors, race conditions, lifecycle issues
  • Security — vulnerabilities, secret exposure, injection
  • API Compatibility — breaking changes, release tags, type design
  • Performance — algorithmic regressions, memory leaks
  • Testing — coverage gaps, hollow tests

How this works

  • Adjust the reviewer set by ticking/unticking boxes above. Reviewer toggles alone don't trigger anything.

  • Tick Start review below to dispatch the review fleet.

  • After review finishes, tick Start review again to request another run — it auto-resets after each dispatch.

  • This comment updates as new commits land; your reviewer selections are preserved.

  • Start review

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 adds a coalescing step to the chunked-forest editing pipeline so that repeated mid-field attach/detach operations don’t leave a field permanently fragmented into many adjacent same-shape UniformChunks. It introduces coalesceAroundSplice as the conceptual inverse of splitFieldAtIndex, merging same-shape UniformChunks along splice seams while respecting the dynamic per-chunk target cap.

Changes:

  • Added coalesceAroundSplice (and internal tryMergeAt) to merge adjacent same-shape UniformChunks around splice seams, capped by uniformChunkNodeCountDynamicTargetMax.
  • Integrated coalescing into ChunkedForest attach/detach edit paths immediately after the underlying splice.
  • Added focused unit tests for coalescing behavior (including caps, shape-equality fallback, refcount behavior, and idCompressor retention) and integration tests verifying coalescing after mid-chunk detach/attach.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
packages/dds/tree/src/feature-libraries/chunked-forest/chunkTree.ts Implements coalesceAroundSplice and merge helper to reduce fragmentation around edit splices.
packages/dds/tree/src/feature-libraries/chunked-forest/chunkedForest.ts Calls coalesceAroundSplice after attach and detach splices to keep fields from fragmenting.
packages/dds/tree/src/test/feature-libraries/chunked-forest/chunkTree.spec.ts Adds a comprehensive test suite for coalesceAroundSplice behavior and edge cases.
packages/dds/tree/src/test/feature-libraries/chunked-forest/chunkedForest.spec.ts Adds integration tests ensuring coalescing occurs after mid-chunk detach/attach edits.

Comment on lines +710 to +714
const merged = new UniformChunk(
leftTreeShape.withTopLevelLength(combinedTopLevel),
[...left.values, ...right.values],
left.idCompressor ?? right.idCompressor,
);
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