1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: MIT OR Apache-2.0
// Copyright (c) 2026 oxml-lsp. All rights reserved.
//! `analyse` must stay fast enough for an editor.
//!
//! This file exists because a benchmark, added at the same time,
//! found `analyse` was quadratic in document size. Nothing else here
//! would have noticed: every correctness test used a small document,
//! and they all passed at 1,088 ms for 480 KB just as they do at 9 ms.
/// `analyse` must stay linear in document size.
///
/// It was quadratic: the duplicate-id check searched a `Vec` linearly
/// and, worse, scanned the whole source to find each id *in the branch
/// where the id was not a duplicate*. A document with five thousand
/// distinct ids performed five thousand full-source scans and reported
/// nothing. A benchmark measured 1.8 ms for 200 entries and 1,088 ms
/// for 5,000 — twenty-six times the input for six hundred times the
/// work. An editor calls this on every keystroke.
///
/// A timing assertion is a blunt instrument and this one is
/// deliberately loose: the fix took the large case to about 10 ms, and
/// the bound is 40 times that. It is not measuring performance, it is
/// catching a return to quadratic, which showed up as a hundredfold
/// difference rather than a subtle one.