merge chunks during attach/detach edits#27386
Conversation
|
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:
How this works
|
There was a problem hiding this comment.
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 internaltryMergeAt) to merge adjacent same-shapeUniformChunks around splice seams, capped byuniformChunkNodeCountDynamicTargetMax. - Integrated coalescing into
ChunkedForestattach/detach edit paths immediately after the underlyingsplice. - 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. |
| const merged = new UniformChunk( | ||
| leftTreeShape.withTopLevelLength(combinedTopLevel), | ||
| [...left.values, ...right.values], | ||
| left.idCompressor ?? right.idCompressor, | ||
| ); |
Description
Follow-up PR to #27153. Adds
coalesceAroundSplice, the inverse ofsplitFieldAtIndex: merges adjacent same-shapeUniformChunks 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-nodeUniformChunkby 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. TheuniformChunkNodeCountDynamicTargetMaxpolicy field added in #27153 explicitly anticipated this work; this PR provides the merge logic it was waiting for.