Skip to content

Visual Studio Code, rebuilt in Rust

Rust

test(editor): gate typing latency on the p95 per edit

rokartur53188dc70d12
diff --git a/native/crates/app/src/syntax.rs b/native/crates/app/src/syntax.rs
index da0a80ef538..e9020f3b29a 100644
--- a/native/crates/app/src/syntax.rs
+++ b/native/crates/app/src/syntax.rs
@@ -857,7 +857,7 @@ mod tests {
/// Typing latency on a 52k-line TypeScript file (textModel.ts repeated): the median per edit of one typed char
/// then the tokens of 60 visible lines, the bracket match, the section headers and the unicode highlights, at lines
- /// 100, 25000 and 49000; the gate is 16 ms. Also the gates of port/notes.md "Scheduling differences".
+ /// 100, 25000 and 49000; the gate is a p95 under 16 ms per edit. Also the gates of port/notes.md "Scheduling differences".
/// Run in release: `cargo gc test --release -p app -- --ignored typing_latency_on_a_large_file --nocapture`.
#[test]
#[ignore]
@@ -918,12 +918,12 @@ mod tests {
background(editor);
frame(editor, 0, 0);
eprintln!("background tokenization and the next frame {:?}", start.elapsed());
- let mut medians = Vec::new();
+ let mut p95s = Vec::new();
for line in [100, 25_000, 49_000] {
editor.move_to(crate::editor::Position::new(line, 0), false);
frame(editor, line, 0);
let mut times = Vec::new();
- for column in 1..=11 {
+ for column in 1..=41 {
let start = Instant::now();
editor.type_text("x").unwrap();
frame(editor, line, column);
@@ -931,8 +931,9 @@ mod tests {
times.push(start.elapsed().as_secs_f64() * 1000.);
}
times.sort_by(f64::total_cmp);
- eprintln!("line {line}: median {:.2} ms, max {:.2} ms", times[5], times[10]);
- medians.push(times[5]);
+ // Nearest-rank p95 of 41 edits is the 39th.
+ eprintln!("line {line}: median {:.2} ms, p95 {:.2} ms, max {:.2} ms", times[20], times[38], times[40]);
+ p95s.push(times[38]);
}
// bracketSelections.ts yields after `_maxDuration` (30 ms): a scan under it gives upstream's ranges.
let mut bracket_scans = Vec::new();
@@ -962,7 +963,7 @@ mod tests {
editor.comment_lines(crate::editor::LineCommentKind::Toggle, true, true, &languages);
let comment = start.elapsed().as_secs_f64() * 1000.;
eprintln!("on a file just opened: trim {trim:.2} ms, comment at line 49000 {comment:.2} ms");
- assert!(medians.iter().all(|&median| median < 16.), "medians {medians:?} ms, the gate is 16 ms");
+ assert!(p95s.iter().all(|&p95| p95 < 16.), "p95 per edit {p95s:?} ms, the gate is 16 ms");
assert!(bracket_scans.iter().all(|&scan| scan < 30.), "bracket selection scans {bracket_scans:?} ms, upstream yields at 30 ms");
assert!(trim < 16. && comment < 16., "trim {trim} ms, comment {comment} ms, the gate is 16 ms");
}
diff --git a/port/notes.md b/port/notes.md
index c15ebc78cf4..b28508e2780 100644
--- a/port/notes.md
+++ b/port/notes.md
@@ -1009,7 +1009,7 @@ GPUI or Rust std limits Artur accepted as differences from 1.147.0; one line eac
## Scheduling differences
-Work the port does at another time than 1.147.0, accepted with a measured same result and typing on a 50k-line TS file under 16 ms per edit. The check, on the Studio in release: `cargo gc test --release -p app -- --ignored typing_latency_on_a_large_file --nocapture` (52156 lines of textModel.ts; each edit is one typed char, the tokens of 60 lines in view, the bracket match, the section headers and the unicode highlights). Measured on worktree-m8-scheduling: median 10.98, 11.62 and 12.45 ms per edit at lines 100, 25000 and 49000, max 13.74 ms.
+Work the port does at another time than 1.147.0, accepted with a measured same result and typing on a 50k-line TS file under 16 ms per edit at p95. The check, on the Studio in release: `cargo gc test --release -p app -- --ignored typing_latency_on_a_large_file --nocapture` (52156 lines of textModel.ts; each edit is one typed char, the tokens of 60 lines in view, the bracket match, the section headers and the unicode highlights). Measured on worktree-m8-scheduling, 41 edits per line, Studio load 3.4: p95 10.07, 11.13 and 11.33 ms per edit at lines 100, 25000 and 49000, max 11.51 ms. Under a load of 76 (five sessions building) the same run reached a median of 16.52 ms and a max of 69 ms, so measure on a quiet Studio.
- Section headers (sectionHeaders.ts) and unicode highlights (unicodeHighlighter.ts `DocumentUnicodeHighlighter`) are found on the UI thread for each model version (minimap_view.rs `minimap_section_labels`, unicode_highlight.rs `unicode_highlights`), where upstream asks the editor worker 250 ms after the last edit and moves the old decorations with the text meanwhile. Same result once upstream's 250 ms pass: the same finders run on the same text, and the section headers read the tokens the lines have (`getLineTokens`, `stored_token_type_at`), found again at most once a second while new tokens arrive (`onDidChangeModelTokens`). Both run inside each edit of the typing check.
-- Smart select's bracket ranges (bracketSelections.ts) scan to the document's ends in one go (smart_select.rs `bracket_ranges`), where upstream yields after `_maxDuration` (30 ms) and stops the right scan after 2 rounds. The scan takes 8.13 to 8.35 ms on the 52k-line file, so upstream's scan ends in its first round with the same ranges; upstream's smartSelect.test.ts raises `_maxDuration` to 5 s for that full scan. The typing check gates the scan under 30 ms.
-- Ported instead (they changed the result): the minimap's sticky sampling (`MinimapSampling::compute` with the last state, `on_lines_deleted`, `on_lines_inserted`, replayed from the model's edit log while view lines are model lines; with word wrap or folds the state is not moved through the edits, an open class 3 gap on the editor/browser row), and `tokenizeIfCheap` and `hasAccurateTokensForLine` in the comment commands and trim trailing whitespace (the action and the save participant). Trim on a file just opened took 6.8 s and comment at line 49000 5.3 s, tokenizing the file; now 3.87 and 14.14 ms, gated under 16 ms by the typing check.
+- Smart select's bracket ranges (bracketSelections.ts) scan to the document's ends in one go (smart_select.rs `bracket_ranges`), where upstream yields after `_maxDuration` (30 ms) and stops the right scan after 2 rounds. The scan takes 7.22 to 7.76 ms on the 52k-line file, so upstream's scan ends in its first round with the same ranges; upstream's smartSelect.test.ts raises `_maxDuration` to 5 s for that full scan. The typing check gates the scan under 30 ms.
+- Ported instead (they changed the result): the minimap's sticky sampling (`MinimapSampling::compute` with the last state, `on_lines_deleted`, `on_lines_inserted`, replayed from the model's edit log while view lines are model lines; with word wrap or folds the state is not moved through the edits, an open class 3 gap on the editor/browser row), and `tokenizeIfCheap` and `hasAccurateTokensForLine` in the comment commands and trim trailing whitespace (the action and the save participant). Trim on a file just opened took 6.8 s and comment at line 49000 5.3 s, tokenizing the file; now 3.70 and 13.53 ms, gated under 16 ms by the typing check.