Visual Studio Code, rebuilt in Rust
Performance
"Fast" is a property the project checks, not a hope. This file has the budgets the port holds today, the rules that keep hot paths fast, how to measure, and the gates that fail on a regression. ARCHITECTURE.md has the map of the code.
The goal: the fastest code editor there is, with every feature of VS Code 1.148.0. Fastest means ahead on every benchmark we can run (startup, input latency, frame time, scroll, open a large file, search, terminal throughput, quit) and the lowest memory (RSS, peak footprint, footprint at idle), against Zed and against every smaller native editor we can measure. A feature is never cut to win a number: the port stays 1:1, and the work goes into making the feature cheap.
The targets are two editors today. VS Code 1.148.0 is the floor: the port must not be worse on a budget, and one budget is (idle CPU). Zed is the bar for a native editor: the port must be ahead of it, and level is a gap. The port is behind Zed on peak memory and RSS (Zed). Another editor joins as a reference through port/tools/bench, the way Zed did.
Budgets
Whole app, measured from outside
port/tools/bench starts the packaged release app on the VS Code checkout (21,627 files) and measures from outside the process. The budgets are the medians of port/results/benchmark.md, kept in port/budgets.json with a noise margin per metric.
| Metric | Budget | Margin | VS Code 1.148.0 |
|---|---|---|---|
Window with the folder (window_s) |
0.66 s | 30% | 0.67 s |
Ready, CPU settled (ready_s) |
2.89 s | 30% | 5.13 s |
CPU time until ready (cpu_s) |
2.42 s | 25% | 7.75 s |
Idle CPU, 60 to 90 s after launch (idle_pct) |
0.5% of a core | 50% | 0.2% |
Quit (quit_s) |
0.13 s | 50% | 0.23 s |
Peak footprint, all processes (peak_footprint_mib) |
488 MiB | 10% | 1042 MiB |
Peak RSS, all processes (peak_rss_mib) |
755 MiB | 10% | 1753 MiB |
Footprint at 90 s (footprint_mib) |
223 MiB | 10% | 584 MiB |
Of that, the extension host (exthost_mib) |
78 MiB | 10% | 108 MiB |
The margins come from the spread of the samples in port/results/benchmark.md. Times vary with the load of the machine, memory does not. The medians come from a machine with a load of 22 to 62, so a quiet machine has room under the time budgets. Idle CPU is the one budget where VS Code is ahead.
Frame times, measured inside tests
| Budget | Gate | Check |
|---|---|---|
| Typing in a 50,000-line TypeScript file | Under 16 ms per edit at p95 | app/src/syntax.rs::typing_latency_on_a_large_file |
| Comment and trim whitespace on that file | Under 16 ms | the same test |
| Scroll frame: Explorer, editor, Extensions, Settings | Under 8 ms at the median and at p95 | app/src/workbench/scroll_frame_time.rs |
| A change inside one part draws only that part | Render counts | app/src/workbench/part_view/tests.rs |
16 ms is one frame at 60 Hz. 8 ms is one frame at 120 Hz. The gate values are constants in the tests, so the test is the one place to change them.
No budget yet
Terminal throughput, time to open a large file and search time have no number and no gate. A budget for one of them starts with a measurement in port/notes.md.
Zed
Zed 1.30.2 is installed on the Studio (/Applications/Zed.app), and port/tools/bench runs it with its own arguments through port/tools/bench-zed. The first run, with the numbers, the definitions for Zed and the command, is in port/notes.md ("Benchmarks", Zed comparison). In that run the port is level with Zed on footprint at 90 s and idle CPU, ahead on CPU until ready and quit, and behind on peak footprint (489 against 378 MiB) and RSS (752 against 560 MiB peak, 363 against 270 MiB at 90 s).
bun port/tools/bench-check.ts <run.tsv> vsrustium zed fails where the port is behind Zed in one run. The against object of port/budgets.json holds a ratio per reference and metric for a difference that is a decision. Frame times need a second method, because the headless tests of the port do not run Zed: the same scroll input in both windows and a sample of the main thread of each.
Rules for hot paths
A hot path is code that runs for each frame, each key or each scroll event: render functions, app/src/workbench/keyboard.rs::key_context, list rows, the editor's lines in view, tokenization.
- No I/O on the main thread in a hot path. No file read, no
stat, no process start, no lock that another thread holds across I/O. Do the work on the background executor or a thread, and bring the result back withcx.spawn. - Work in proportion to what is in view, not to what exists. A list lays out the rows in view. The editor shapes the lines in view. The minimap and the overview ruler read their own viewport.
- Compute once where the state changes, not each time it is read. A regex is compiled once. A value derived from settings is kept until the settings change. A folder listing is kept until its modification time changes (
app/src/explorer.rs::FileTree). - Notify the smallest view.
cx.notify()on theWorkbenchdraws every part. A scroll, a cursor blink or a late answer for one editor notifies its part view (app/src/workbench/part_view.rs::notify_editor_view). Notify only after a real change. - No allocation storm per frame. Do not build a
Vecor aStringper row or per token for data that did not change. Keep it with the state. - Tokenize and parse in slices. Long work on a document yields, runs in the background, or uses the cheap path upstream uses.
- Measure before and after. A change to a hot path comes with the numbers of its gate from before and after the change, from the same machine in the same hour.
Each rule has a regression behind it. port/notes.md ("Benchmarks", "Scheduling differences") has the cases: 14 regexes compiled per row made a settings scroll frame take 37 ms. A folder read on each key_context call made an Explorer frame take 36 ms where 13 ms was possible. A notify of the Workbench for an inlay hint answer drew every part on 78 of 87 scroll frames.
How to measure
Measure a release build. The debug profile builds the port's crates without optimization (native/Cargo.toml), so a debug build is much slower and points at the wrong places.
- The whole app:
port/tools/bench. Its header has the method.port/results/benchmark.mdhas the full command and how to read the numbers. - Frame times without a window: the ignored tests of Budgets, with
cargo gc test --release -p app -- --ignored <name> --nocapture. They draw a real workbench without a GPU. - A benchmark of one GPUI path with Criterion: the skill in
.agents/skills/gpui-benchhas the rules. The main one: notest-supportfeature in a benchmark, or it measures test code. - Where the time goes:
sample <pid>or Instruments (Time Profiler,xctrace record --template 'Time Profiler') on the release app. For "who caused this draw", add#[track_caller]logging tonotifyfor the run. - Startup phases:
Developer: Startup Performancein the app shows thecode/...marks ofapp/src/perf.rs.
The machine is shared, and its load changes a time by about 30%. Check the load before a timing run. port/tools/bench-check.ts prints a note when the load of the run was over 10: a time over its budget is then no result, and the run must be done again. A memory number is a result at any load.
The gates
| Gate | Command | Fails when |
|---|---|---|
| Whole-app budgets | port/tools/bench > run.tsv, then bun port/tools/bench-check.ts run.tsv |
A median is over its budget by more than its margin |
| Typing | cargo gc test --release -p app -- --ignored typing_latency_on_a_large_file --nocapture |
p95 per edit is 16 ms or more |
| Scroll frames | cargo gc test --release -p app -- --ignored scroll_frame_time --nocapture --test-threads=1 |
A median or p95 is 8 ms or more. The same filter runs app/src/workbench/scroll_frame_time.rs::terminal_typing_frame_time: p95 per frame is 16 ms or more |
| Render counts | port/tools/cargo-test part_view |
A part draws that did not change |
| Quick Open | cargo gc test --release -p app -- --ignored quick_open_keystroke_time --nocapture |
Scoring 100,000 files takes 150 ms or more per keystroke |
| Memory over a session | port/tools/studio --lane 'port/tools/memory-soak' with MODE browse, typing or all, after port/tools/package-app |
The window process's footprint over the last 5 rounds is over 1.3 times that of rounds 3 to 7 (port/notes.md, issue 116) |
port/tools/bench-check.ts reads the output of port/tools/bench and port/budgets.json. It prints each metric with its limit and exits 1 on a failure. port/tools/bench-check.test.ts shows it red on a planted regression.
Where the gates run:
- On the Studio, by hand, before a release and after a change to a hot path. The three timing gates need a release build and a quiet machine.
- In a CI run only the render counts can run, with the other tests. They count draws, so they do not depend on the speed of the runner.
- Timing gates do not run on GitHub runners. A shared runner varies by more than the margins. A gate that fails at random gets ignored.
A budget changes only with a measurement. To lower one after an improvement, run the bench, put the new medians in port/budgets.json and in port/results/benchmark.md, in one commit. To raise one, the commit says what was bought with the cost.