src/vs/base/browser/ui/tree/indexTreeModel.ts/IndexTreeModel/spliceSmart
class IndexTreeModel:	private spliceSmart(
		identity: IIdentityProvider<T>,
		location: number[],
		deleteCount: number,
		toInsertIterable: Iterable<ITreeElement<T>> = Iterable.empty(),
		options: IIndexTreeModelSpliceOptions<T, TFilterData>,
		recurseLevels = options.diffDepth ?? 0,
	) {
		const { parentNode } = this.getParentNodeWithListIndex(location);
		if (!parentNode.lastDiffIds) {
			return this.spliceSimple(location, deleteCount, toInsertIterable, options);
		}

		const toInsert = [...toInsertIterable];
		const index = location[location.length - 1];
		const diff = new LcsDiff(
			{ getElements: () => parentNode.lastDiffIds! },
			{
				getElements: () => [
					...parentNode.children.slice(0, index),
					...toInsert,
					...parentNode.children.slice(index + deleteCount),
				].map(e => identity.getId(e.element).toString())
			},
		).ComputeDiff(false);

		// if we were given a 'best effort' diff, use default behavior
		if (diff.quitEarly) {
			parentNode.lastDiffIds = undefined;
			return this.spliceSimple(location, deleteCount, toInsert, options);
		}

		const locationPrefix = location.slice(0, -1);
		const recurseSplice = (fromOriginal: number, fromModified: number, count: number) => {
			if (recurseLevels > 0) {
				for (let i = 0; i < count; i++) {
					fromOriginal--;
					fromModified--;
					this.spliceSmart(
						identity,
						[...locationPrefix, fromOriginal, 0],
						Number.MAX_SAFE_INTEGER,
						toInsert[fromModified].children,
						options,
						recurseLevels - 1,
					);
				}
			}
		};

		let lastStartO = Math.min(parentNode.children.length, index + deleteCount);
		let lastStartM = toInsert.length;
		for (const change of diff.changes.sort((a, b) => b.originalStart - a.originalStart)) {
			recurseSplice(lastStartO, lastStartM, lastStartO - (change.originalStart + change.originalLength));
			lastStartO = change.originalStart;
			lastStartM = change.modifiedStart - index;

			this.spliceSimple(
				[...locationPrefix, lastStartO],
				change.originalLength,
				Iterable.slice(toInsert, lastStartM, lastStartM + change.modifiedLength),
				options,
			);
		}

		// at this point, startO === startM === count since any remaining prefix should match
		recurseSplice(lastStartO, lastStartM, lastStartO);
	}