-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workaround for huge idmap diffs (#9207)
Fixes probably #9198 See [this comment](#9198 (comment)) for justification. TLDR: the diff algorithm is too slow for our huge idmap. The proper fix would be to reduce idmap size. Expect tasks for that soon.
- Loading branch information
Showing
5 changed files
with
170 additions
and
16 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
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,60 @@ | ||
import diff from 'fast-diff' | ||
import { uuidv4 } from 'lib0/random.js' | ||
import { bench, describe } from 'vitest' | ||
import { stupidFastDiff } from '../edits' | ||
|
||
describe('Diff algorithm benchmarks', () => { | ||
let oldString = '' | ||
let newString = '' | ||
|
||
function initializeStrings(length: number) { | ||
// simulating metadata list: | ||
oldString = '' | ||
let i = 0 | ||
while (oldString.length < length / 2) { | ||
oldString += `[{"index":{"value":${i}},"size":{"value":4}},"${uuidv4()}"]` | ||
i += 1 | ||
} | ||
i = 1 | ||
newString = '' | ||
while (newString.length < length / 2) { | ||
newString += `[{"index":{"value":${i}},"size":{"value":5}},"${uuidv4()}"]` | ||
} | ||
} | ||
|
||
function diffBenchmark(length: number) { | ||
bench( | ||
`Diffing ${length}`, | ||
() => { | ||
diff(oldString, newString) | ||
}, | ||
{ setup: () => initializeStrings(length), warmupIterations: 1, iterations: 1 }, | ||
) | ||
} | ||
|
||
function stupidFastDiffBenchmark(length: number) { | ||
bench( | ||
`Fast Diffing ${length}`, | ||
() => { | ||
stupidFastDiff(oldString, newString) | ||
}, | ||
{ setup: () => initializeStrings(length), warmupIterations: 1, iterations: 1 }, | ||
) | ||
} | ||
|
||
diffBenchmark(10000) | ||
diffBenchmark(20000) | ||
diffBenchmark(30000) | ||
diffBenchmark(40000) | ||
diffBenchmark(50000) | ||
// These are too slow for every-day benchmark run | ||
// diffBenchmark(60000) | ||
// diffBenchmark(70000) | ||
// diffBenchmark(80000) | ||
// diffBenchmark(90000) | ||
// diffBenchmark(100000) | ||
// diffBenchmark(250000) | ||
|
||
stupidFastDiffBenchmark(250000) | ||
stupidFastDiffBenchmark(2500000) | ||
}) |
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