Skip to content

Benchmark TSP against LSP for a cold start on PyTorch (#5438) - #5438

Closed
kinto0 wants to merge 3 commits into
meta:mainfrom
kinto0:export-D128200923
Closed

kinto0 wants to merge 3 commits into
meta:mainfrom
kinto0:export-D128200923

Conversation

@kinto0

@kinto0 kinto0 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

Stack context: TSP vs pyrefly LSP latency benchmarks on PyTorch.

  • What: add tsp/pytorch_cold_start to benches/tsp/pytorch.rs. Each sample starts a fresh server, initializes it, and opens torch/_inductor/ir.py. LSP: then textDocument/diagnostic. TSP: then a replay of the 17,494 requests that Pylance sent after opening the file until it went quiet, mostly its background checker's sweep of the file plus ~1.1k resolveImport.
  • Why: opening a slow file is where TSP costs the most. The sweep on open touches the same ~90 dependency modules as a re-check, but none of them are solved yet.

Differential Revision: D128200923

Summary:
Stack context: TSP vs pyrefly LSP latency benchmarks on PyTorch.

- What: add `benches/tsp/record/`, which runs the latest VS Code and Pylance headless with pyrefly as the type server, opens `torch/_inductor/ir.py` in the pinned PyTorch checkout, and drives a hover, a completion, and an idle re-check after edits. It writes every TSP request Pylance sent to `benches/tsp/traces/`, one file per feature (`cold_start`, `hover`, `completion`, `recheck`; ~1 MB in total, checked in), so that each benchmark loads only its own trace and a re-recording diffs per feature.
- Why: TSP benchmarks need the requests a real client sends. Hand-written sequences guess wrong: Pylance sends no requests for a repeated hover (it caches types until the snapshot changes), never sends `getDeclaredType`, and re-checks the whole file over TSP after every edit and on open.
- Foreground requests come from pyrefly's stdin. Background-checker requests go over an extra connection, so they come from Pylance's own TSP log, which the runner copies as it grows because VS Code rotates it every 5 MB.

Differential Revision: D128200913
Summary:
Stack context: TSP vs pyrefly LSP latency benchmarks on PyTorch.

- What: add `benches/tsp/pytorch.rs` to `tsp_bench`. Each sample edits `torch/_inductor/ir.py` and serves one feature through the language server (`lsp`) and through the type server (`tsp`), which replays the recorded Pylance requests for the same feature from `benches/tsp/traces/`:
  - `tsp/pytorch_hover`: hover on `guard_or_false`. Pylance: 33 requests (`getSnapshot`, one `resolveImport` per import, `getComputedType`).
  - `tsp/pytorch_completion`: completion after `V.graph.sizevars.`. Pylance: 79 requests.
  - `tsp/pytorch_recheck`: the diagnostics of the file. LSP: `textDocument/diagnostic`. Pylance: the ~16.5k `getComputedType` requests that its background checker sends after every edit.
- Why: a TSP client turns one IDE action into many TSP requests, so TSP latency can regress without any LSP benchmark moving.
- Both servers run in process, driven by the shared `pyrefly_lsp_test` client, with the same pinned-checkout resource as `pytorch_bench`. The replay fills in the current snapshot and retries on `snapshot outdated`, as Pylance does. Each request stream is measured alone, although in Pylance the background checker shares the server's queue with hover and completion.

Differential Revision: D128185161
Summary:
Stack context: TSP vs pyrefly LSP latency benchmarks on PyTorch.

- What: add `tsp/pytorch_cold_start` to `benches/tsp/pytorch.rs`. Each sample starts a fresh server, initializes it, and opens `torch/_inductor/ir.py`. LSP: then `textDocument/diagnostic`. TSP: then a replay of the 17,494 requests that Pylance sent after opening the file until it went quiet, mostly its background checker's sweep of the file plus ~1.1k `resolveImport`.
- Why: opening a slow file is where TSP costs the most. The sweep on open touches the same ~90 dependency modules as a re-check, but none of them are solved yet.

Differential Revision: D128200923
@meta-cla meta-cla Bot added the cla signed label Oct 29, 2026
@meta-codesync

meta-codesync Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@kinto0 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D128200923.

@kinto0

kinto0 commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by the stacked PRs #5439, #5440, and #5441. This export put all three commits on one fork branch, which cannot be stacked.

@kinto0 kinto0 closed this Oct 29, 2026
@meta-codesync meta-codesync Bot changed the title Benchmark TSP against LSP for a cold start on PyTorch Oct 30, 2026
kinto0 added a commit to kinto0/pyrefly that referenced this pull request Oct 30, 2026
Summary:

Stack context: TSP vs pyrefly LSP latency benchmarks on PyTorch.

- What: add `tsp/pytorch_cold_start` to `benches/tsp/pytorch.rs`. Each sample starts a fresh server, initializes it, and opens `torch/_inductor/ir.py`. LSP: then `textDocument/diagnostic`. TSP: then a replay of the 17,494 requests that Pylance sent after opening the file until it went quiet, mostly its background checker's sweep of the file plus ~1.1k `resolveImport`.
- Why: opening a slow file is where TSP costs the most. The sweep on open touches the same ~90 dependency modules as a re-check, but none of them are solved yet.

Differential Revision: D128200923
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

1 participant