Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/dds/tree/api-report/tree.alpha.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ export type ConciseTree<THandle = IFluidHandle> = Exclude<TreeLeafValue, IFluidH
[key: string]: ConciseTree<THandle>;
};

// @alpha
export function configuredSharedTreeAlpha(options: SharedTreeOptions): SharedObjectKind<ITree>;

// @beta
export function configuredSharedTreeBeta(options: SharedTreeOptionsBeta): SharedObjectKind<ITree>;

Expand Down Expand Up @@ -427,6 +430,15 @@ export type ImplicitFieldSchema = FieldSchema | ImplicitAllowedTypes;
// @alpha
export function importCompatibilitySchemaSnapshot(config: JsonCompatibleReadOnly): TreeViewConfiguration;

// @alpha
export type IncrementalEncodingPolicy = (nodeIdentifier: string | undefined, fieldKey: string) => boolean;

// @alpha
export function incrementalEncodingPolicyForAllowedTypes(rootSchema: TreeSchema): IncrementalEncodingPolicy;

// @alpha
export const incrementalSummaryHint: unique symbol;

// @alpha
export function independentInitializedView<const TSchema extends ImplicitFieldSchema>(config: TreeViewConfiguration<TSchema>, options: ForestOptions & ICodecOptions, content: ViewContent): TreeViewAlpha<TSchema>;

Expand Down Expand Up @@ -1022,8 +1034,9 @@ export interface SharedTreeFormatOptions {
}

// @alpha @input
export interface SharedTreeOptions extends Partial<CodecWriteOptions>, Partial<SharedTreeFormatOptions>, SharedTreeOptionsBeta {
export interface SharedTreeOptions extends SharedTreeOptionsBeta, Partial<CodecWriteOptions>, Partial<SharedTreeFormatOptions> {
readonly enableSharedBranches?: boolean;
shouldEncodeIncrementally?: IncrementalEncodingPolicy;
}

// @beta @input
Expand Down Expand Up @@ -1475,6 +1488,7 @@ export interface TreeChangeEventsBeta<TNode extends TreeNode = TreeNode> extends
// @alpha
export enum TreeCompressionStrategy {
Compressed = 0,
CompressedIncremental = 2,
Uncompressed = 1
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ import {
type Brand,
type JsonCompatibleReadOnly,
} from "../../../util/index.js";
import {
TreeCompressionStrategy,
TreeCompressionStrategyExtended,
type TreeCompressionStrategyPrivate,
} from "../../treeCompressionUtils.js";
import { TreeCompressionStrategy } from "../../treeCompressionUtils.js";

import { decode } from "./chunkDecoding.js";
import type { FieldBatch } from "./fieldBatch.js";
Expand Down Expand Up @@ -109,7 +105,7 @@ export interface IncrementalDecoder {
export interface IncrementalEncoderDecoder extends IncrementalEncoder, IncrementalDecoder {}

export interface FieldBatchEncodingContext {
readonly encodeType: TreeCompressionStrategyPrivate;
readonly encodeType: TreeCompressionStrategy;
readonly idCompressor: IIdCompressor;
readonly originatorId: SessionId;
readonly schema?: SchemaAndPolicy;
Expand Down Expand Up @@ -190,7 +186,7 @@ export function makeFieldBatchCodec(options: CodecWriteOptions): FieldBatchCodec
case TreeCompressionStrategy.Uncompressed:
encoded = uncompressedEncodeFn(data);
break;
case TreeCompressionStrategyExtended.CompressedIncremental:
case TreeCompressionStrategy.CompressedIncremental:
assert(
writeVersion >= FieldBatchFormatVersion.v2,
"Unsupported FieldBatchFormatVersion for incremental encoding; must be v2 or higher",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* Licensed under the MIT License.
*/

import type { FieldKey, TreeNodeSchemaIdentifier } from "../../../core/index.js";

/**
* Policy to determine whether a node / field should be incrementally encoded.
* @param nodeIdentifier - The identifier of the node containing the field.
Expand All @@ -16,18 +14,19 @@ import type { FieldKey, TreeNodeSchemaIdentifier } from "../../../core/index.js"
* but allows reuse of previously encoded unchanged subtrees.
* Thus it should only be enabled for large subtrees which are modified infrequently.
* TODO: AB#9068: Measure the actual overhead.
* @alpha
*/
export type IncrementalEncodingPolicy = (
nodeIdentifier: TreeNodeSchemaIdentifier | undefined,
fieldKey: FieldKey,
nodeIdentifier: string | undefined,
fieldKey: string,
) => boolean;

/**
* Default policy for incremental encoding is to not encode incrementally.
*/
export const defaultIncrementalEncodingPolicy: IncrementalEncodingPolicy = (
nodeIdentifier: TreeNodeSchemaIdentifier | undefined,
fieldKey: FieldKey,
nodeIdentifier: string | undefined,
fieldKey: string,
): boolean => {
return false;
};
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import {
ForestIncrementalSummaryBuilder,
forestSummaryContentKey,
} from "./incrementalSummaryBuilder.js";
import { TreeCompressionStrategyExtended } from "../treeCompressionUtils.js";
import { TreeCompressionStrategy } from "../treeCompressionUtils.js";
import type { IFluidHandle } from "@fluidframework/core-interfaces";

/**
Expand Down Expand Up @@ -85,7 +85,7 @@ export class ForestSummarizer implements Summarizable {
this.codec = makeForestSummarizerCodec(options, fieldBatchCodec);
this.incrementalSummaryBuilder = new ForestIncrementalSummaryBuilder(
encoderContext.encodeType ===
TreeCompressionStrategyExtended.CompressedIncremental /* enableIncrementalSummary */,
TreeCompressionStrategy.CompressedIncremental /* enableIncrementalSummary */,
(cursor: ITreeCursorSynchronous) => this.forest.chunkField(cursor),
shouldEncodeIncrementally,
initialSequenceNumber,
Expand Down
6 changes: 1 addition & 5 deletions packages/dds/tree/src/feature-libraries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,7 @@ export {
type Observer,
} from "./flex-tree/index.js";

export {
TreeCompressionStrategy,
TreeCompressionStrategyExtended,
type TreeCompressionStrategyPrivate,
} from "./treeCompressionUtils.js";
export { TreeCompressionStrategy } from "./treeCompressionUtils.js";

export { valueSchemaAllows } from "./valueUtilities.js";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ import {
chunkFieldSingle,
defaultChunkPolicy,
} from "../chunked-forest/index.js";
import {
TreeCompressionStrategy,
type TreeCompressionStrategyPrivate,
} from "../treeCompressionUtils.js";
import { TreeCompressionStrategy } from "../treeCompressionUtils.js";

import type { FieldChangeEncodingContext, FieldChangeHandler } from "./fieldChangeHandler.js";
import type {
Expand Down Expand Up @@ -81,7 +78,7 @@ export function makeModularChangeCodecFamily(
>,
fieldsCodec: FieldBatchCodec,
codecOptions: ICodecOptions,
chunkCompressionStrategy: TreeCompressionStrategyPrivate = TreeCompressionStrategy.Compressed,
chunkCompressionStrategy: TreeCompressionStrategy = TreeCompressionStrategy.Compressed,
): ICodecFamily<ModularChangeset, ChangeEncodingContext> {
return makeCodecFamily(
Array.from(fieldKindConfigurations.entries(), ([version, fieldKinds]) => [
Expand Down Expand Up @@ -121,7 +118,7 @@ function makeModularChangeCodec(
>,
fieldsCodec: FieldBatchCodec,
codecOptions: ICodecOptions,
chunkCompressionStrategy: TreeCompressionStrategyPrivate = TreeCompressionStrategy.Compressed,
chunkCompressionStrategy: TreeCompressionStrategy = TreeCompressionStrategy.Compressed,
): ModularChangeCodec {
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
const getMapEntry = ({ kind, formatVersion }: FieldKindConfigurationEntry) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,9 @@ export enum TreeCompressionStrategy {
* Use this when debugging or testing and needing to inspect encoded tree content.
*/
Uncompressed = 1,
}

/**
* A private extension of {@link TreeCompressionStrategy} for strategies that are not intended for public use just yet.
*/
export enum TreeCompressionStrategyExtended {
/**
* Optimized for encoded size, same as TreeCompressionStrategy.Compressed. It also enables incremental encoding
* Optimized for encoded size, same as TreeCompressionStrategy.Compressed but it enables incremental encoding
* of the data.
* @remarks
* TODO: AB#41865
* This needs to be stabilized to allow opting into it.
* It could possibly be made the default instead of {@link TreeCompressionStrategy.Compressed}.
*/
CompressedIncremental = 2,
}

export type TreeCompressionStrategyPrivate =
| TreeCompressionStrategy
| TreeCompressionStrategyExtended;
4 changes: 4 additions & 0 deletions packages/dds/tree/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export {
type TreeIndex,
type TreeIndexKey,
type TreeIndexNodes,
type IncrementalEncodingPolicy,
} from "./feature-libraries/index.js";

export {
Expand Down Expand Up @@ -287,10 +288,13 @@ export {
exportCompatibilitySchemaSnapshot,
importCompatibilitySchemaSnapshot,
checkCompatibility,
incrementalSummaryHint,
incrementalEncodingPolicyForAllowedTypes,
} from "./simple-tree/index.js";
export {
SharedTree,
configuredSharedTree,
configuredSharedTreeAlpha,
configuredSharedTreeBeta,
configuredSharedTreeBetaLegacy,
} from "./treeFactory.js";
Expand Down
2 changes: 1 addition & 1 deletion packages/dds/tree/src/shared-tree-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export {
type SummaryElementParser,
type SummaryElementStringifier,
type ClonableSchemaAndPolicy,
type SharedTreeCoreOptionsInternal as SharedTreCoreOptionsInternal,
type SharedTreeCoreOptionsInternal,
} from "./sharedTreeCore.js";

export type { ResubmitMachine } from "./resubmitMachine.js";
Expand Down
30 changes: 12 additions & 18 deletions packages/dds/tree/src/shared-tree/sharedTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ import {
makeSchemaCodec,
makeTreeChunker,
type IncrementalEncodingPolicy,
type TreeCompressionStrategyPrivate,
} from "../feature-libraries/index.js";
// eslint-disable-next-line import-x/no-internal-modules
import type { FormatV1 } from "../feature-libraries/schema-index/index.js";
Expand All @@ -75,7 +74,7 @@ import {
type ClonableSchemaAndPolicy,
getCodecTreeForEditManagerFormatWithChange,
getCodecTreeForMessageFormatWithChange,
type SharedTreCoreOptionsInternal,
type SharedTreeCoreOptionsInternal,
MessageFormatVersion,
SharedTreeCore,
EditManagerFormatVersion,
Expand Down Expand Up @@ -656,26 +655,19 @@ export function getCodecTreeForSharedTreeFormat(
export type SharedTreeOptionsBeta = ForestOptions;

/**
* Configuration options for SharedTree.
* Configuration options for SharedTree with alpha features.
* @alpha @input
*/
export interface SharedTreeOptions
extends Partial<CodecWriteOptions>,
Partial<SharedTreeFormatOptions>,
SharedTreeOptionsBeta {
extends SharedTreeOptionsBeta,
Partial<CodecWriteOptions>,
Partial<SharedTreeFormatOptions> {
/**
* Experimental feature flag to enable shared branches.
* This feature is not yet complete and should not be used in production.
* Defaults to false.
*/
readonly enableSharedBranches?: boolean;
}

export interface SharedTreeOptionsInternal
extends Partial<SharedTreCoreOptionsInternal>,
Partial<ForestOptions>,
Partial<SharedTreeFormatOptionsInternal> {
disposeForksAfterTransaction?: boolean;
/**
* Returns whether a node / field should be incrementally encoded.
* @remarks
Expand All @@ -684,6 +676,12 @@ export interface SharedTreeOptionsInternal
shouldEncodeIncrementally?: IncrementalEncodingPolicy;
}

export interface SharedTreeOptionsInternal
extends Partial<SharedTreeOptions>,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this should be a Partial. If SharedTreeOptionsPublic or Beta or Alpha has a required parameter, then SharedTreeOptionsInternal needs to supply that as well to be compatible.

Partial<SharedTreeCoreOptionsInternal> {
disposeForksAfterTransaction?: boolean;
}

/**
* Configuration options for SharedTree's internal tree storage.
* @beta @input
Expand All @@ -707,11 +705,6 @@ export interface SharedTreeFormatOptions {
treeEncodeType: TreeCompressionStrategy;
}

export interface SharedTreeFormatOptionsInternal
extends Omit<SharedTreeFormatOptions, "treeEncodeType"> {
treeEncodeType: TreeCompressionStrategyPrivate;
}

/**
* Used to distinguish between different forest types.
* @remarks
Expand Down Expand Up @@ -814,6 +807,7 @@ export const defaultSharedTreeOptions: Required<SharedTreeOptionsInternal> = {
shouldEncodeIncrementally: defaultIncrementalEncodingPolicy,
editManagerFormatSelector: clientVersionToEditManagerFormatVersion,
messageFormatSelector: clientVersionToMessageFormatVersion,
enableSharedBranches: false,
};

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/dds/tree/src/shared-tree/sharedTreeChangeFamily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
ModularChangeFamily,
type ModularChangeset,
type TreeChunk,
type TreeCompressionStrategyPrivate,
type TreeCompressionStrategy,
fieldKindConfigurations,
fieldKinds,
makeModularChangeCodecFamily,
Expand Down Expand Up @@ -61,7 +61,7 @@ export class SharedTreeChangeFamily
revisionTagCodec: RevisionTagCodec,
fieldBatchCodec: FieldBatchCodec,
codecOptions: CodecWriteOptions,
chunkCompressionStrategy?: TreeCompressionStrategyPrivate,
chunkCompressionStrategy?: TreeCompressionStrategy,
private readonly idCompressor?: IIdCompressor,
) {
const modularChangeCodec = makeModularChangeCodecFamily(
Expand Down
4 changes: 2 additions & 2 deletions packages/dds/tree/src/shared-tree/treeCheckout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import {
} from "../core/index.js";
import {
type FieldBatchCodec,
type TreeCompressionStrategyPrivate,
type TreeCompressionStrategy,
allowsRepoSuperset,
buildForest,
createNodeIdentifierManager,
Expand Down Expand Up @@ -287,7 +287,7 @@ export function createTreeCheckout(
forest?: IEditableForest;
fieldBatchCodec?: FieldBatchCodec;
removedRoots?: DetachedFieldIndex;
chunkCompressionStrategy?: TreeCompressionStrategyPrivate;
chunkCompressionStrategy?: TreeCompressionStrategy;
logger?: ITelemetryLoggerExt;
breaker?: Breakable;
disposeForksAfterTransaction?: boolean;
Expand Down
Loading
Loading