Skip to content

Commit 66f6533

Browse files
author
Alec Gibson
committed
Improve performance of getLinkedOps
Running `getOps` to fetch a large number of operations is not very performant. Anecdotally, performing this operation on a local development machine with a document comprising of ~200,000 operations takes ~20s. The largest slow-down appears to come from the `getLinkedOps` method, and in particular the use of `Array.unshift`. This change makes a very simple change that `push`es to the array instead of `unshift`, and then `reverse`s it at the end. The anecdotal operation time using this modified function is now ~2s, which is an improvement of an order of magnitude.
1 parent 5a7c674 commit 66f6533

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,10 @@ function getLinkedOps(ops, to, link) {
534534
if (to == null || op.v < to) {
535535
delete op._id;
536536
delete op.o;
537-
linkedOps.unshift(op);
537+
linkedOps.push(op);
538538
}
539539
}
540-
return linkedOps;
540+
return linkedOps.reverse();
541541
}
542542

543543
function getOpsQuery(id, from) {

0 commit comments

Comments
 (0)