forked from microsoft/FluidFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(split from Whiteboard) Merged PR 32084: perf: Optimize getStartingPoint
This PR aims to optimize `getStartingPoint(Number.POSITIVE_INFINITY)` when no local changes exist by caching the edit with the highest revision in CachingLogViewer. See approach \#3 from #59391 **Before Optimization Perf Results**: ``` status name period (ns/op) root mean error iterations samples total time (s) ------ ------------------------------------------- -------------- --------------- ---------- ------- -------------- ✔ get currentView with 1 sequenced edit(s) 256.3 ±5.32% 19,175,112 71 5.59 ✔ get currentView with 1000 sequenced edit(s) 678.1 ±4.80% 7,157,358 73 5.43 ``` **After Optimization Perf Results**: ``` status name period (ns/op) root mean error iterations samples total time (s) ------ ----------------------------------------- -------------- --------------- ---------- ------- -------------- ✔ get currentView with 1 sequenced edits 151.4 ±4.39% 32,649,075 81 5.57 ✔ get currentView with 1000 sequenced edits 178.3 ±4.38% 27,418,925 79 5.50 ``` Related work items: #59651
- Loading branch information
1 parent
a1f9898
commit bed2bad
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/*! | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
import { benchmark, BenchmarkType } from '@fluid-tools/benchmark'; | ||
import { MockContainerRuntimeFactory } from '@fluidframework/test-runtime-utils'; | ||
import { assert } from '../Common'; | ||
import { Change, SharedTree } from '../default-edits'; | ||
import { EditLog } from '../EditLog'; | ||
import { createStableEdits, setUpTestSharedTree, simpleTestTree } from './utilities/TestUtilities'; | ||
|
||
describe('SharedTree Perf', () => { | ||
let tree: SharedTree | undefined; | ||
let containerRuntimeFactory: MockContainerRuntimeFactory | undefined; | ||
for (const count of [1, 1_000]) { | ||
benchmark({ | ||
type: BenchmarkType.Measurement, | ||
title: `get currentView with ${count} sequenced edit(s)`, | ||
before: () => { | ||
({ tree, containerRuntimeFactory } = setUpTestSharedTree({ initialTree: simpleTestTree })); | ||
|
||
const edits = createStableEdits(count); | ||
for (let i = 0; i < count - 1; i++) { | ||
tree.processLocalEdit(edits[i]); | ||
} | ||
|
||
containerRuntimeFactory.processAllMessages(); | ||
const editLog = tree.edits as EditLog<Change>; | ||
assert(editLog.numberOfSequencedEdits === count); | ||
assert(editLog.numberOfLocalEdits === 0); | ||
}, | ||
benchmarkFn: () => { | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
tree!.currentView; | ||
}, | ||
after: () => { | ||
tree = undefined; | ||
containerRuntimeFactory = undefined; | ||
}, | ||
}); | ||
} | ||
}); |