Skip to content

perf(lsp): increase concurrency level by available threads - #25153

Merged
leaysgur merged 3 commits into
mainfrom
07-31-perf_lsp_increase_concurrency_level_by_available_threads
Aug 31, 2026
Merged

leaysgur merged 3 commits into
mainfrom
07-31-perf_lsp_increase_concurrency_level_by_available_threads

Conversation

@Sysix

@Sysix Sysix commented Jul 31, 2026 •

Copy link
Copy Markdown
Member

Adjusts the Oxc language server startup to scale Tower LSP request handling concurrency based on the machine’s available parallelism, aiming to improve throughput on higher-core systems without fully saturating the host.

The saturation is from personal feeling and did not get benchmarked.

Sysix commented Jul 31, 2026

Copy link
Copy Markdown
Member Author

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent changes, fast-track this PR to the front of the merge queue

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions Bot added the A-editor Area - Language server and editor integrations label Jul 31, 2026
@Sysix
Sysix requested a review from Copilot July 31, 2026 13:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts the Oxc language server startup to scale Tower LSP request handling concurrency based on the machine’s available parallelism, aiming to improve throughput on higher-core systems without fully saturating the host.

Changes:

  • Compute an effective concurrency target from std::thread::available_parallelism() (with a small “leave headroom” heuristic).
  • Configure tower_lsp_server::Server with .concurrency_level(...) instead of using the default.
Suppressed comments (1)

crates/oxc_language_server/src/lib.rs:64

  • available_parallelism() returns a NonZeroUsize on success, so NonZero::get won’t resolve here. Use |n| n.get() (or NonZeroUsize::get) to extract the usize.
    let current_threads = std::thread::available_parallelism().map_or(1, NonZero::get);

Comment thread crates/oxc_language_server/src/lib.rs Resolved
@Sysix
Sysix force-pushed the 07-31-perf_lsp_increase_concurrency_level_by_available_threads branch from 6808abe to b49f196 Compare August 6, 2026 19:47
@Sysix
Sysix marked this pull request as ready for review August 6, 2026 19:55
@Sysix
Sysix requested review from camc314 and leaysgur as code owners August 6, 2026 19:55
Comment thread crates/oxc_language_server/src/lib.rs Resolved
Sysix added a commit that referenced this pull request Aug 23, 2026
…ers to prevent deadlock (#25438)

## What this PR does

Fixes the permanent language-server deadlock reported in #24955.

`workspace/diagnostic/refresh` is a server-to-client *request*, and a
spec-compliant client may re-pull `textDocument/diagnostic` from this
same server before replying to it. Three notification handlers
(`initialized`, `did_change_configuration`, `did_change_watched_files`)
awaited that round-trip inside the handler itself, pinning one of the
transport's concurrency slots (tower-lsp-server defaults to 4) for as
long as the client took to reply. Four rapid watcher events — e.g. four
saves of `.oxlintrc.json` or any `tsconfig*.json` in pull-diagnostic
mode — pinned all four slots on handlers waiting for the client, while
the client waited on diagnostic pulls the server could no longer
service. Circular wait, no timeout, no recovery until the process is
killed.

The refresh is advisory — nothing consumes its result beyond logging a
warning — so this PR detaches it: a new
`Backend::spawn_diagnostic_refresh()` clones the client and spawns the
round-trip, returning the handler's slot immediately. The server keeps
answering requests with any number of refresh replies outstanding. This
is the issue's first suggested fix; raising the concurrency level
(#25153) only widens the window rather than closing it, as the issue
notes.

## How it's tested

`test_outstanding_diagnostic_refreshes_do_not_wedge_the_server` runs in
the crate's existing wire-level `TestServer` harness — real LSP framing
over duplex streams, the real `Server` at its real default concurrency
of 4. It initializes in pull mode with dynamic watchers, fires four
watched-file events, reads each resulting `workspace/diagnostic/refresh`
request **without replying** (what a busy client looks like), then sends
`shutdown` and requires a response within a 10s timeout.

Verified both directions: against the previous code the test fails by
timeout at exactly the reported wedge point; with the fix, the full
crate suite passes (85/85). `cargo fmt` and `clippy --all-targets` are
clean for the changed files. The only other change is adding tokio's
`time` feature to dev-dependencies for the test's timeout.

## AI disclosure

Investigated, implemented, and verified with AI assistance (Claude
Code), per the contributing guide's disclosure policy. I traced the root
cause to the transport's concurrency accounting, confirmed the circular
wait matches the reporter's reproduction, and validated the fix with the
deadlock-reproducing regression test above before submission.

Co-authored-by: Alexander S. <[email protected]>
@leaysgur

Copy link
Copy Markdown
Member

It seems we can close this as of #25438.

@leaysgur leaysgur closed this Aug 26, 2026
@Sysix

Sysix commented Aug 29, 2026

Copy link
Copy Markdown
Member Author

@leaysgur sorry for not replies, I did not had time to create tests for concurrency level 1. Normally it should not change anything, but #25438 showed that communication channel can block itself.

Even so #25438 fixed a problem, this PR could be improved performance in general, maybe we add a Math.min(4) so it can not be lower then today.

@leaysgur leaysgur reopened this Aug 30, 2026
@leaysgur

Copy link
Copy Markdown
Member

🙆🏻 Let’s reopen then. Can you update and finish?

@leaysgur leaysgur assigned Sysix and unassigned leaysgur Aug 30, 2026
@Sysix
Sysix force-pushed the 07-31-perf_lsp_increase_concurrency_level_by_available_threads branch from b49f196 to 42cdbc9 Compare August 30, 2026 15:42
@Sysix
Sysix requested a lite review from Copilot August 30, 2026 15:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread crates/oxc_language_server/src/lib.rs Resolved
Comment thread crates/oxc_language_server/src/lib.rs Resolved
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
Signed-off-by: Alexander S. <[email protected]>
@Sysix Sysix assigned leaysgur and unassigned Sysix Aug 30, 2026
Comment thread crates/oxc_language_server/src/lib.rs Resolved
@leaysgur
leaysgur enabled auto-merge (squash) August 31, 2026 00:23
@leaysgur
leaysgur merged commit 409b4e2 into main Aug 31, 2026
30 checks passed
@leaysgur
leaysgur deleted the 07-31-perf_lsp_increase_concurrency_level_by_available_threads branch August 31, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-editor Area - Language server and editor integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants