From d399756eec3f975b7b93cb2de69ef8fdd1e57949 Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Thu, 24 Apr 2025 19:49:08 +0200 Subject: [PATCH] more work on optimizing. Improve the test case. --- tests/y-text.tests.js | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/tests/y-text.tests.js b/tests/y-text.tests.js index 0b552756..53da8631 100644 --- a/tests/y-text.tests.js +++ b/tests/y-text.tests.js @@ -2606,30 +2606,44 @@ const checkResult = result => { } /** + * Generally, the content reader with attributed content works better if there is more deleted + * content. Increasing the number of deletions improves performance of getContent (even to the point + * that is beats toString(), but that might be because of internal js optimization steps). + * * @param {t.TestCase} tc */ export const testAttributionManagerDefaultPerformance = tc => { const N = 100000 + const MaxDeletionLength = 5 // 25% chance of deletion + const MaxInsertionLength = 5 const ydoc = new Y.Doc() const ytext = ydoc.getText() for (let i = 0; i < N; i++) { - if (prng.bool(tc.prng) && ytext.length > 0) { + if (prng.bool(tc.prng) && prng.bool(tc.prng) && ytext.length > 0) { const index = prng.int31(tc.prng, 0, ytext.length - 1) - const len = prng.int31(tc.prng, 0, math.min(ytext.length - index, 5)) + const len = prng.int31(tc.prng, 0, math.min(ytext.length - index, MaxDeletionLength)) ytext.delete(index, len) } else { const index = prng.int31(tc.prng, 0, ytext.length) - const content = prng.utf16String(tc.prng, 30) + const content = prng.utf16String(tc.prng, MaxInsertionLength) ytext.insert(index, content) } } + t.info(`number of changes: ${N/1000}k`) + t.info(`length of text: ${ytext.length}`) const M = 100 - t.measureTime('original toDelta perf', () => { + + t.measureTime(`original toString perf `, () => { for (let i = 0; i < M; i++) { ytext.toDelta() } }) - t.measureTime('getContent(attributionManager) performance)', () => { + t.measureTime(`original toDelta perf `, () => { + for (let i = 0; i < M; i++) { + ytext.toDelta() + } + }) + t.measureTime(`getContent(attributionManager) performance `, () => { for (let i = 0; i < M; i++) { ytext.getContent() }