Perf: Unexpected quadratic performance loading a collaborative text document
I'm benchmarking automerge as a point of comparison in a paper I'm writing. And I'm running into a strange problem:
I have a dataset containing an editing trace made by 2 users working on a document together, live. The editing trace is quite short (only a few kilobytes of text). So I'm enlarging it by 25x to make it comparable with other tests.
The original trace takes 87ms to replay - which is not too bad. I would expect the 25x larger version to take 25x longer (or maybe 25 × log(25) or something). But instead, the 25x version takes 2 minutes (120 000ms) to run. This seems suspiciously close to 25^2 times slower. (Its 25252.1x slower. But a 2.1x constant factor would be expected just from the extra cache misses of a larger data set).
It seems like something strange is going on. For comparison, other similarly duplicated tests I'm running are behaving as expected.
I'm using the latest automerge 0.5.9 from cargo.
The two traces are linked in the zip file below. This code is enough to reproduce the problem:
fn load_am(filename: &str) {
let bytes = std::fs::read(&filename).unwrap();
let doc = Automerge::load(&bytes).unwrap(); // <-- This is the slow part.
}
fn main() {
load_am("C1_fast.am");
load_am("C1_slow.am");
}(This is all in release mode)
Source: automerge/automerge