Skip to content

refactor(tree): adopt range-only detached index APIs - #11

Draft
Abe27342 wants to merge 4 commits into
abe27342-range-stack-visitorfrom
abe27342-range-stack-index
Draft

Abe27342 wants to merge 4 commits into
abe27342-range-stack-visitorfrom
abe27342-range-stack-index

Conversation

@Abe27342

Copy link
Copy Markdown
Owner

How contribute to this repo.

Guidelines for Pull Requests.

Description

Replace singleton-only detached index queries and the construction mode with an unconditional location/range API.
Migrate all consumers while retaining singleton field production at this checkpoint.
The scalar expansion helper preserves node indices, mutations re-resolve detached IDs, and legacy format restrictions remain at the codec boundary.

Make range clipping easier to follow by skipping records before the requested interval, stopping after it, and clipping both ends explicitly while preserving empty-range behavior.
Document that the fieldToRanges runs, concatenated in array order, describe the complete field contents.

Layer 2 of 5 in a draft, review-only fork stack.
Depends on Abe27342/FluidFramework#10.
Relates to AB#5509.

Breaking Changes

None to the supported package surface; the detached index API is internal.

Reviewer Guidance

The review process is outlined in the pull request guidelines.

Focus on range lookup and maximal present or missing prefixes, revision splits, offset repair, snapshot invalidation, explicit scalar adapters, and unchanged legacy summary order.

Parent-run validation at the original layer checkpoint, 3897685c53ba260dbbc8c812c37eeb005d82909d:

  • pnpm -C packages\dds\tree build — PASSED.
  • pnpm -C packages\dds\tree test — FAILED with one known baseline Windows snapshotCompatibilityChecker path mismatch, reproduced on the unchanged base; 9 production smoke tests and 13,703 ESM tests passed, with 365 pending.

Parent-run complete-stack validation also passed the build and had 13,774 ESM tests passing, with the same sole baseline failure.

Parent-run validation of the readability refinement on the full source at 9e0b0594f9345dde85738aba3787e8487818872c:

  • Biome — PASSED.
  • pnpm -C packages\dds\tree build:esm — PASSED.
  • pnpm -C packages\dds\tree build:test:esm — PASSED.
  • pnpm -C packages\dds\tree test:mocha:esm --grep 'DetachedFieldIndex' --reporter dot — PASSED, 101 tests.

The refinement was cherry-picked unchanged onto this layer as ce1c401db6fa346363dfe6396dcd9f49c8033a7e.
No new tests were run in this isolated publishing worktree; additional CI readiness was explicitly skipped.

Abram Sanderson (He/Him) and others added 2 commits November 20, 2026 11:08
Replace field-only queries and index creation modes with unconditional range/location APIs. Keep scalar field production and consumers explicit, preserve offsets through a read-only expansion adapter, and enforce legacy format restrictions in codecs rather than index queries.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Separate out-of-range filtering from start/end clipping, retain empty-range behavior, and document that ordered runs describe a detached field's complete contents.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Describe the range-to-location invariant, the meaning of root/index, whole-field registration, removal compaction, retention boundaries, and caller-owned forest coordination.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Abe27342
Abe27342 added this pull request to stack #15 November 20, 2026 20:25
Preserve the user's example and wording refinements, and document why the revision sets use the same internal immutable record instances as the field index.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
* Preserves legacy major and minor insertion order without expanding grouped fields.
* Each field is created with one major ID, and removing nodes or changing lifetimes does not change it.
* A major keeps its position until its last field is removed.
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm having trouble understanding how the comment and the declaration relate to one-another. How does a an order-free data structure help with preserving the order of something?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Looks to be talking about the map iteration order, which is documented in the js map spec.

Not clear to me why the implementation should care about that though, so it's fair feedback.

(already told Yann offline to not worry too much about this until I make a pass over it)

*/
public deleteRange(root: ForestRootId, range: Range): void {
this.getFieldRanges(root, range);
const count = range.end - range.start;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why this invocation of getFieldRanges?

* Values are offset to the queried node's index within its forest field.
*/
private readonly detachedNodeToField = new RangeMap<
Delta.DetachedNodeId,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The seems to be a lot of overlap between what 1majorToFieldsand fieldToRangesstore and whatdetachedNodeToField` stores. Why do we need both?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

detachedNodeToField efficiently allows one to go from detached node ID ranges to ranges of content in the forest.

fieldToRanges is the reverse lookup: get all detached node ids (expressed as a union of ranges) for a particular detached field in the forest.

Having this reverse lookup is important for internal bookkeeping. Let's establish shorthand as follows: use letters for major revisions and numbers for minors. I'll also denote contents of fields without range-expression shorthand, but of course runs like [A0, A1, A2, A3, A4] would be expressed as [{ major: A, minor: 0, count: 5}] as in the top comment.

Before this change, the shape of the query API was effectively "getForestRootId(detachedNodeId): ForestRootId".

As this change modifies the index to representing detached forest content as ranges, that shape changes. Detached operations of length N are still given one id, and to uniquely address individual nodes in that field you additionally need an index. The query method now has an API like getForestRootLocation(detachedNodeId): { id: ForestRootId, index: number }. The crux of the reason why the reverse mapping is useful is because it allows efficiently updating forward mapping information about indexes when the start of a field changes.

Suppose the detached field index has a field with contents [A0, A1, A2, B2, B3] at some point in time, and it needs to process an edit that causes A0 to be moved to a new detached field (or the attached tree, or whatever). This edit needs to update bookkeeping such that not just the result of getForestRootLocation(A0) changes, but also the same query for any of A1, A2, B2, or B3, since all of their indices go down by 1. Storing a reverse mapping "field -> detached node ids that occupy that field" is the simplest way to accomplish this.

majorToFields has dubious value, see other comment.

This is good feedback though, and I'll try and incorporate some of the description here into the doc comments on Monday.

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