Sub topic 11
When only the editor is slow: tsserver logs
Assume you can read TypeScript generics and unions, edit tsconfig.json, and run tsc with npm or npx. This chapter focuses on a different problem from a slow build: the command-line compiler may finish quickly while autocomplete, navigation, or diagnostics lag in the editor.
Understand the TypeScript language server
The TypeScript language server, called tsserver, is the background process that powers editor features. It keeps projects in memory and answers requests such as:
- “What type does this expression have?”
- “Which symbols match these characters?”
- “Find all references to this function.”
- “Show diagnostics for this file.”
The editor sends requests to tsserver. The server loads a project, builds or updates its program, checks types, and sends a response.
A slow response can come from project loading, repeated graph updates, expensive type checking, or an editor extension sending many requests. A slow tsc run does not always explain an editor slowdown because the editor may use a different TypeScript version, configuration, or project.
Turn on a server log
In Visual Studio Code, open workspace settings as JSON and add:
{
"typescript.tsserver.log": "verbose"
}Run TypeScript: Restart TS Server from the command palette. Reproduce the slowdown for a short period, then run TypeScript: Open TS Server log. Copy the log to a safe location before turning logging off:
{
"typescript.tsserver.log": "off"
}The exact setting name and commands depend on the editor. Other editors often expose the same tsserver options through a TypeScript or language-server setting.
You can also start the server directly when testing outside an editor:
npx tsserver --logVerbosity verbose --logFile tsserver.logThis command starts a protocol server and waits for requests. It is most useful when another tool launches it or when you are inspecting a controlled reproduction.
Read the useful parts
A log is a chronological record, not a profile summary. Start by finding the time range in which you reproduced the problem. Look for these signals:
| Log signal | What it suggests | Next check |
|---|---|---|
| Long request duration | One editor operation is expensive | Identify the request and file |
| `updateGraph` or project reload | The project is repeatedly rebuilding | Check watched files and configuration |
| Many `geterr` requests | Diagnostics are being requested often | Check editor extensions and file changes |
| Large project file lists | The project scope may be too broad | Inspect `include`, `exclude`, and imports |
On macOS or Linux, search a saved log with:
rg -n "requestTime|updateGraph|ProjectService|open files|geterr" tsserver.logOn Windows, use the editor's log search or PowerShell:
Select-String -Path .\tsserver.log -Pattern "requestTime|updateGraph|ProjectService|geterr"A request that takes hundreds or thousands of milliseconds is worth investigating. Compare its file and operation with a fast request. For example, completion in one file may be slow because that file imports a type-heavy module, while completion elsewhere remains normal.
Separate server slowness from editor slowness
Use a small test matrix:
- Run
npx tsc --noEmitand record its time. - Open the same file in the editor and test completion or “Go to Definition.”
- Disable nonessential editor extensions temporarily.
- Check which TypeScript version the editor uses.
- Compare the active project with the
tsconfig.jsonyou tested from the command line.
If tsc and tsserver are both slow, investigate program scope and expensive types. If only tsserver is slow, inspect project reloads, watched files, editor extensions, and multiple workspace roots.
A repeated reload often means a generated file, build output, or dependency directory is inside the project or watched by the editor. Keep generated output outside src, and use exclude for directories that should not belong to the project.
Verify the change
Capture a short log before changing configuration. Make one change, restart tsserver, reproduce the same action, and capture another short log. Compare:
- the duration of the same request,
- the number of project reloads,
- the files listed during project updates,
- the TypeScript version and project configuration.
Do not judge the fix from a single click. Repeat the action several times after the server cache is warm. A fix that reduces one request but causes constant project reloads has moved the problem rather than solved it.
Exercise
The command-line build takes 300 ms, but completion in one file takes 2 seconds. What should you inspect first?
Show answer
Capture a short verbose tsserver log and identify the slow completion request, its project, and any nearby project reload or updateGraph activity. Then check whether an extension, a broad project scope, or a type-heavy import affects that file.