@fluidframework/merge-tree 2.0.0-internal.4.1.2 → 2.0.0-internal.4.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -152,11 +152,6 @@ export declare class MergeTree {
152
152
  private minSeqListeners;
153
153
  mergeTreeDeltaCallback?: MergeTreeDeltaCallback;
154
154
  mergeTreeMaintenanceCallback?: MergeTreeMaintenanceCallback;
155
- /**
156
- * If we remove a contiguous range of segments, avoid duplicated tree traversal
157
- * for each segment removed, as this scales poorly
158
- */
159
- private cachedSlideDestination;
160
155
  constructor(options?: IMergeTreeOptions | undefined);
161
156
  private _root;
162
157
  get root(): IRootMergeBlock;
@@ -192,16 +187,29 @@ export declare class MergeTree {
192
187
  /**
193
188
  * @remarks Must only be used by client.
194
189
  * @param segment - The segment to slide from.
195
- * @param shouldCache - Whether to cache the sliding destination for this segment.
196
- * @returns The segment to.
190
+ * @param cache - Optional cache mapping segments to their sliding destinations.
191
+ * Excursions will be avoided for segments in the cache, and the cache will be populated with
192
+ * entries for all segments visited during excursion.
193
+ * This can reduce the number of times the tree needs to be scanned if a range containing many
194
+ * SlideOnRemove references is removed.
195
+ * @returns The segment a SlideOnRemove reference should slide to, or undefined if there is no
196
+ * valid segment (i.e. the tree is empty).
197
197
  * @internal
198
198
  */
199
- _getSlideToSegment(segment: ISegment | undefined, shouldCache?: boolean): ISegment | undefined;
199
+ _getSlideToSegment(segment: ISegment | undefined, cache?: Map<ISegment, {
200
+ seg?: ISegment;
201
+ }>): ISegment | undefined;
200
202
  /**
201
- * This method should only be called when the current client sequence number is
203
+ * Slides or removes references from the provided list of segments.
204
+ * The order of the references is preserved.
205
+ * @remarks -
206
+ * 1. Preserving the order of the references is a useful property for reference-based undo/redo
207
+ * (see revertibles.ts).
208
+ * 2. For use cases which necessitate eventual consistency across clients,
209
+ * this method should only be called with segments for which the current client sequence number is
202
210
  * max(remove segment sequence number, add reference sequence number).
203
- * Otherwise eventual consistency is not guaranteed.
204
211
  * See `packages\dds\merge-tree\REFERENCEPOSITIONS.md`
212
+ * @param segments - An array of (not necessarily contiguous) segments with increasing ordinals.
205
213
  */
206
214
  private slideAckedRemovedSegmentReferences;
207
215
  private blockLength;
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTree.d.ts","sourceRoot":"","sources":["../src/mergeTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AASH,OAAO,EAAE,gCAAgC,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAY,KAAK,EAAE,MAAM,eAAe,CAAC;AAQtE,OAAO,EAA4B,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACpF,OAAO,EAIN,mBAAmB,EAEnB,WAAW,EACX,UAAU,EAEV,mBAAmB,EAInB,QAAQ,EACR,cAAc,EAId,UAAU,EACV,SAAS,EAIT,YAAY,EAEZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,qBAAqB,EAErB,sBAAsB,EACtB,4BAA4B,EAE5B,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACN,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EAEjB,aAAa,EACb,MAAM,OAAO,CAAC;AAEf,OAAO,EAA8B,WAAW,EAAE,MAAM,cAAc,CAAC;AACvE,OAAO,EAEN,iBAAiB,EAEjB,aAAa,EAKb,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAUhE,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AA4TlC;;;GAGG;AACH,MAAM,WAAW,SAAS;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,iBAAiB;IACjC,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;;;;;OAUG;IACH,iCAAiC,CAAC,EAAE,OAAO,CAAC;IAC5C,0BAA0B,CA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AmBG;IACI,yBAAyB,IAAI,IAAI;IAmCxC,OAAO,CAAC,WAAW;IA2BZ,sBAAsB,CAC5B,UAAU,EAAE,WAAW,GAAG,SAAS,EACnC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,YAAY,UAAQ;IAarB,OAAO,CAAC,iBAAiB;IAoBlB,QAAQ,CAAC,WAAW,EAC1B,OAAO,EAAE,cAAc,CAAC,WAAW,CAAC,EACpC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,WAAW,EAClB,KAAK,CAAC,EAAE,MAAM,EACd,GAAG,CAAC,EAAE,MAAM,EACZ,UAAU,GAAE,OAAe;IAarB,mBAAmB,CAAC,QAAQ,EAAE,UAAU,EAAE,KAAK,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAuDrF,OAAO,CAAC,OAAO;CAoDf"}
package/dist/mergeTree.js CHANGED
@@ -535,92 +535,111 @@ class MergeTree {
535
535
  /**
536
536
  * @remarks Must only be used by client.
537
537
  * @param segment - The segment to slide from.
538
- * @param shouldCache - Whether to cache the sliding destination for this segment.
539
- * @returns The segment to.
538
+ * @param cache - Optional cache mapping segments to their sliding destinations.
539
+ * Excursions will be avoided for segments in the cache, and the cache will be populated with
540
+ * entries for all segments visited during excursion.
541
+ * This can reduce the number of times the tree needs to be scanned if a range containing many
542
+ * SlideOnRemove references is removed.
543
+ * @returns The segment a SlideOnRemove reference should slide to, or undefined if there is no
544
+ * valid segment (i.e. the tree is empty).
540
545
  * @internal
541
546
  */
542
- _getSlideToSegment(segment, shouldCache) {
543
- var _a, _b, _c, _d;
547
+ _getSlideToSegment(segment, cache) {
544
548
  if (!segment || !isRemovedAndAcked(segment)) {
545
549
  return segment;
546
550
  }
547
- if (((_a = this.cachedSlideDestination) === null || _a === void 0 ? void 0 : _a.seq) !== segment.removedSeq && shouldCache) {
548
- this.cachedSlideDestination = {
549
- segmentToSlideDestination: new Map(),
550
- seq: segment.removedSeq,
551
- };
552
- }
553
- // cache slide destination of segments to improve the pathological case
554
- // in which we slide the same segment multiple times
555
- const cachedSegment = (_b = this.cachedSlideDestination) === null || _b === void 0 ? void 0 : _b.segmentToSlideDestination.get(segment);
556
- if (cachedSegment !== undefined && shouldCache) {
557
- return cachedSegment === "detached" ? undefined : cachedSegment;
551
+ const cachedSegment = cache === null || cache === void 0 ? void 0 : cache.get(segment);
552
+ if (cachedSegment !== undefined) {
553
+ return cachedSegment.seg;
558
554
  }
559
- const segmentsWithSlidDst = new Set();
560
- let slideToSegment;
555
+ const result = {};
556
+ cache === null || cache === void 0 ? void 0 : cache.set(segment, result);
561
557
  const goFurtherToFindSlideToSegment = (seg) => {
562
558
  if (seg.seq !== constants_1.UnassignedSequenceNumber && !isRemovedAndAcked(seg)) {
563
- slideToSegment = seg;
559
+ result.seg = seg;
564
560
  return false;
565
561
  }
566
- segmentsWithSlidDst.add(seg);
562
+ if (cache !== undefined && seg.removedSeq === segment.removedSeq) {
563
+ cache.set(seg, result);
564
+ }
567
565
  return true;
568
566
  };
569
567
  // Slide to the next farthest valid segment in the tree.
570
568
  (0, mergeTreeNodeWalk_1.forwardExcursion)(segment, goFurtherToFindSlideToSegment);
571
- if (slideToSegment) {
572
- if (shouldCache) {
573
- for (const seg of segmentsWithSlidDst) {
574
- (_c = this.cachedSlideDestination) === null || _c === void 0 ? void 0 : _c.segmentToSlideDestination.set(seg, slideToSegment);
575
- }
576
- }
577
- return slideToSegment;
569
+ if (result.seg !== undefined) {
570
+ return result.seg;
578
571
  }
579
572
  // If no such segment is found, slide to the last valid segment.
580
573
  (0, mergeTreeNodeWalk_1.backwardExcursion)(segment, goFurtherToFindSlideToSegment);
581
- if (shouldCache) {
582
- for (const seg of segmentsWithSlidDst) {
583
- (_d = this.cachedSlideDestination) === null || _d === void 0 ? void 0 : _d.segmentToSlideDestination.set(seg, slideToSegment !== null && slideToSegment !== void 0 ? slideToSegment : "detached");
584
- }
585
- }
586
- return slideToSegment;
574
+ return result.seg;
587
575
  }
588
576
  /**
589
- * This method should only be called when the current client sequence number is
577
+ * Slides or removes references from the provided list of segments.
578
+ * The order of the references is preserved.
579
+ * @remarks -
580
+ * 1. Preserving the order of the references is a useful property for reference-based undo/redo
581
+ * (see revertibles.ts).
582
+ * 2. For use cases which necessitate eventual consistency across clients,
583
+ * this method should only be called with segments for which the current client sequence number is
590
584
  * max(remove segment sequence number, add reference sequence number).
591
- * Otherwise eventual consistency is not guaranteed.
592
585
  * See `packages\dds\merge-tree\REFERENCEPOSITIONS.md`
586
+ * @param segments - An array of (not necessarily contiguous) segments with increasing ordinals.
593
587
  */
594
- slideAckedRemovedSegmentReferences(segment) {
595
- var _a, _b, _c, _d, _e, _f, _g;
596
- (0, common_utils_1.assert)(isRemovedAndAcked(segment), 0x2f1 /* slideReferences from a segment which has not been removed and acked */);
597
- if (((_a = segment.localRefs) === null || _a === void 0 ? void 0 : _a.empty) !== false) {
598
- return;
599
- }
600
- const newSegment = this._getSlideToSegment(segment, true);
601
- if (newSegment) {
602
- const localRefs = ((_b = newSegment.localRefs) !== null && _b !== void 0 ? _b : (newSegment.localRefs = new localReference_1.LocalReferenceCollection(newSegment)));
603
- if (newSegment.ordinal < segment.ordinal) {
604
- localRefs.addAfterTombstones(segment.localRefs);
588
+ slideAckedRemovedSegmentReferences(segments) {
589
+ // References are slid in groups to preserve their order.
590
+ let currentSlideDestination;
591
+ let currentSlideIsForward;
592
+ let currentSlideGroup = [];
593
+ const slideGroup = () => {
594
+ var _a, _b, _c, _d, _e;
595
+ if (currentSlideIsForward !== undefined) {
596
+ if (currentSlideDestination !== undefined) {
597
+ const localRefs = ((_a = currentSlideDestination.localRefs) !== null && _a !== void 0 ? _a : (currentSlideDestination.localRefs = new localReference_1.LocalReferenceCollection(currentSlideDestination)));
598
+ if (currentSlideIsForward) {
599
+ localRefs.addBeforeTombstones(...currentSlideGroup);
600
+ }
601
+ else {
602
+ localRefs.addAfterTombstones(...currentSlideGroup);
603
+ }
604
+ }
605
+ else {
606
+ for (const collection of currentSlideGroup) {
607
+ for (const ref of collection) {
608
+ if (!(0, referencePositions_1.refTypeIncludesFlag)(ref, ops_1.ReferenceType.StayOnRemove)) {
609
+ (_c = (_b = ref.callbacks) === null || _b === void 0 ? void 0 : _b.beforeSlide) === null || _c === void 0 ? void 0 : _c.call(_b, ref);
610
+ collection.removeLocalRef(ref);
611
+ (_e = (_d = ref.callbacks) === null || _d === void 0 ? void 0 : _d.afterSlide) === null || _e === void 0 ? void 0 : _e.call(_d, ref);
612
+ }
613
+ }
614
+ }
615
+ }
616
+ // TODO:AB#4069: This update might be avoidable by checking if the old segment
617
+ // had hierarchical refs before sliding using `segment.localRefs?.hierRefCount`.
618
+ if (currentSlideDestination) {
619
+ this.blockUpdatePathLengths(currentSlideDestination.parent, constants_1.TreeMaintenanceSequenceNumber, constants_1.LocalClientId);
620
+ }
605
621
  }
606
- else {
607
- localRefs.addBeforeTombstones(segment.localRefs);
622
+ };
623
+ const segmentCache = new Map();
624
+ for (const segment of segments) {
625
+ (0, common_utils_1.assert)(isRemovedAndAcked(segment), 0x2f1 /* slideReferences from a segment which has not been removed and acked */);
626
+ if (segment.localRefs === undefined || segment.localRefs.empty) {
627
+ continue;
608
628
  }
609
- }
610
- else {
611
- for (const ref of segment.localRefs) {
612
- if (!(0, referencePositions_1.refTypeIncludesFlag)(ref, ops_1.ReferenceType.StayOnRemove)) {
613
- (_d = (_c = ref.callbacks) === null || _c === void 0 ? void 0 : _c.beforeSlide) === null || _d === void 0 ? void 0 : _d.call(_c, ref);
614
- (_e = segment.localRefs) === null || _e === void 0 ? void 0 : _e.removeLocalRef(ref);
615
- (_g = (_f = ref.callbacks) === null || _f === void 0 ? void 0 : _f.afterSlide) === null || _g === void 0 ? void 0 : _g.call(_f, ref);
616
- }
629
+ const slideToSegment = this._getSlideToSegment(segment, segmentCache);
630
+ const slideIsForward = slideToSegment === undefined ? false : slideToSegment.ordinal > segment.ordinal;
631
+ if (slideToSegment !== currentSlideDestination ||
632
+ slideIsForward !== currentSlideIsForward) {
633
+ slideGroup();
634
+ currentSlideGroup = [segment.localRefs];
635
+ currentSlideDestination = slideToSegment;
636
+ currentSlideIsForward = slideIsForward;
637
+ }
638
+ else {
639
+ currentSlideGroup.push(segment.localRefs);
617
640
  }
618
641
  }
619
- // TODO:AB#4069: This update might be avoidable by checking if the old segment
620
- // had hierarchical refs before sliding using `segment.localRefs?.hierRefCount`.
621
- if (newSegment) {
622
- this.blockUpdatePathLengths(newSegment.parent, constants_1.TreeMaintenanceSequenceNumber, constants_1.LocalClientId);
623
- }
642
+ slideGroup();
624
643
  }
625
644
  blockLength(node, refSeq, clientId) {
626
645
  return this.collabWindow.collaborating && clientId !== this.collabWindow.clientId
@@ -940,25 +959,7 @@ class MergeTree {
940
959
  // Perform slides after all segments have been acked, so that
941
960
  // positions after slide are final
942
961
  if (opArgs.op.type === ops_1.MergeTreeDeltaType.REMOVE) {
943
- // if the slide destination is further, then we have to slide
944
- // references in reverse to preserve their order
945
- const newSegment = this._getSlideToSegment(pendingSegmentGroup.segments[0]);
946
- const shouldReverse = pendingSegmentGroup.segments[0] &&
947
- newSegment &&
948
- pendingSegmentGroup.segments[0].ordinal < newSegment.ordinal;
949
- let idx = shouldReverse ? pendingSegmentGroup.segments.length - 1 : 0;
950
- while (idx >= 0 && idx < pendingSegmentGroup.segments.length) {
951
- const pendingSegment = pendingSegmentGroup.segments[idx];
952
- if (!overlappingRemoves[idx]) {
953
- this.slideAckedRemovedSegmentReferences(pendingSegment);
954
- }
955
- if (shouldReverse) {
956
- idx--;
957
- }
958
- else {
959
- idx++;
960
- }
961
- }
962
+ this.slideAckedRemovedSegmentReferences(pendingSegmentGroup.segments);
962
963
  }
963
964
  (_b = this.mergeTreeMaintenanceCallback) === null || _b === void 0 ? void 0 : _b.call(this, {
964
965
  deltaSegments,
@@ -1537,7 +1538,7 @@ class MergeTree {
1537
1538
  this.nodeMap(refSeq, clientId, markRemoved, undefined, afterMarkRemoved, start, end);
1538
1539
  // these segments are already viewed as being removed locally and are not event-ed
1539
1540
  // so can slide non-StayOnRemove refs immediately
1540
- localOverlapWithRefs.forEach((s) => this.slideAckedRemovedSegmentReferences(s));
1541
+ this.slideAckedRemovedSegmentReferences(localOverlapWithRefs);
1541
1542
  // opArgs == undefined => test code
1542
1543
  if (removedSegments.length > 0) {
1543
1544
  (_a = this.mergeTreeDeltaCallback) === null || _a === void 0 ? void 0 : _a.call(this, opArgs, {
@@ -1549,9 +1550,7 @@ class MergeTree {
1549
1550
  // so we slide after eventing in case the consumer wants to make reference
1550
1551
  // changes at remove time, like add a ref to track undo redo.
1551
1552
  if (!this.collabWindow.collaborating || clientId !== this.collabWindow.clientId) {
1552
- removedSegments.forEach((rSeg) => {
1553
- this.slideAckedRemovedSegmentReferences(rSeg.segment);
1554
- });
1553
+ this.slideAckedRemovedSegmentReferences(removedSegments.map(({ segment }) => segment));
1555
1554
  }
1556
1555
  if (this.collabWindow.collaborating && seq !== constants_1.UnassignedSequenceNumber) {
1557
1556
  if (MergeTree.options.zamboniSegments) {