diff --git a/tests/y-text.tests.js b/tests/y-text.tests.js index ad4fbc5d..dbb61457 100644 --- a/tests/y-text.tests.js +++ b/tests/y-text.tests.js @@ -368,6 +368,42 @@ export const testLargeFragmentedDocument = tc => { })() } +/** + * @param {t.TestCase} tc + */ +export const testIncrementalUpdatesPerformanceOnLargeFragmentedDocument = tc => { + const itemsToInsert = largeDocumentSize + const updates = /** @type {Array} */ ([]) + ;(() => { + const doc1 = new Y.Doc() + doc1.on('update', update => { + updates.push(update) + }) + const text0 = doc1.getText('txt') + tryGc() + t.measureTime(`time to insert ${itemsToInsert} items`, () => { + doc1.transact(() => { + for (let i = 0; i < itemsToInsert; i++) { + text0.insert(0, '0') + } + }) + }) + tryGc() + })() + ;(() => { + t.measureTime(`time to merge ${itemsToInsert} updates (differential updates)`, () => { + Y.mergeUpdates(updates) + }) + tryGc() + t.measureTime(`time to merge ${itemsToInsert} updates (ydoc updates)`, () => { + const ydoc = new Y.Doc() + updates.forEach(update => { + Y.applyUpdate(ydoc, update) + }) + }) + })() +} + /** * Splitting surrogates can lead to invalid encoded documents. *