Skip to content

fix(lsp): let the session hold its server weakly - #837

Merged
Boshen merged 1 commit into
mainfrom
max/lsp-session-weak-client
Oct 29, 2026
Merged

Boshen merged 1 commit into
mainfrom
max/lsp-session-weak-client

Conversation

@maschwenk

@maschwenk maschwenk commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

the lsp server owns its session, and the session held two Arc<Server> back (its project client and npm executor). so a server dropped without a shutdown request never freed the session, its snapshots or its programs. that hits every in-process server: the tsrs_lsp integration tests (lsptestutil never sends shutdown) and a future napi build.

the session now gets a private SessionClient(Weak<Server>) that forwards while the server is alive and does nothing after, same as the logger already does. the new test fails on main and passes here.

one change in the binary: if an editor closes stdin without sending shutdown, tsrs --lsp now frees the session right before exiting instead of just exiting.

ported from effect's tsrs patch, mattia is co-author on the commit:

numbers on macOS, debug test profile:

main this PR
tsrs_lsp integration suite peak RSS 311-316 MiB 195-212 MiB
40 open/hover/drop server cycles, no shutdown 630 MiB 64 MiB

with a shutdown first, main already frees almost everything (about 0.2 MiB per cycle), so the fourslash job wont move much. the suite also passes with TSRS_ARENA_POISON=1, which matters since tests never freed these sessions and programs before.

part of #646 (leaks through repeated LSP lifecycles)

The server owns its session and the session held two `Arc<Server>` (its project client and npm executor), so a
dropped in-process server never freed the session, its snapshots or its programs. The session now gets a
`SessionClient(Weak<Server>)` that forwards while the server is alive and does nothing after, like the logger.

Ported from Effect-TS/tsgo's tsrs patch 102.

Co-authored-by: Mattia Manzati <mattia.manzati@gmail.com>
@maschwenk
maschwenk force-pushed the max/lsp-session-weak-client branch from ae016a1 to 6ab09d5 Compare October 28, 2026 13:16
@codspeed

codspeed Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 8 untouched benchmarks
⏩ 8 skipped benchmarks1


Comparing max/lsp-session-weak-client (6ab09d5) with main (5535cad)

Open in CodSpeed

Footnotes

  1. 8 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Performance change vs main

Workflow run · main 5535cadb3b12 → PR merge a10d2ae23962 (head 6ab09d5aedee)

Clef gate: Running benchmarks because the decision was unavailable (crates/tsrs_lsp/src/server.rs: patch exceeds the Clef context limit (4215 bytes)).

Release builds in fast mode (TSRS_FAST=1) with Hyperfine 2 hardware counters. After warming each binary, alternating main/PR pairs measure wall time at both the fast preset's default checker count and with --singleThreaded, with ten pairs per configuration by default. Instructions come from the single-threaded runs; peak RSS comes from the default-count runs.
Incremental runs start with fresh build info before every invocation; check runs disable incremental compilation.

Project Mode Single-thread wall time Δ Single-thread instructions Δ Default wall time Δ Default peak RSS Δ
vscode check -6.1% 0.000% -3.1% -0.1%
vscode incremental +1.6% +0.002% +0.4% +0.1%
xstate-main check -0.9% +0.001% +1.1% -0.2%
xstate-main incremental -3.3% -0.001% +0.2% +0.1%
webpack check -2.7% 0.000% -1.9% -0.4%
webpack incremental -1.6% -0.004% -7.6% 0.0%
mui-docs check +0.2% -0.003% -2.0% -0.3%
mui-docs incremental +0.2% +0.007% +2.4% +0.4%
Compiler check -3.7% 0.000% -2.3% +0.7%
Compiler incremental -2.9% 0.000% +2.7% +0.1%
Compiler-Unions check -5.3% 0.000% +2.6% -0.2%
Compiler-Unions incremental +1.0% 0.000% -5.0% +0.3%
cal-diy check -0.8% -0.001% -1.2% +0.3%
cal-diy incremental -1.1% 0.000% -0.6% +0.1%
formbricks-web check +3.7% -0.001% +2.4% 0.0%
formbricks-web incremental +2.2% +0.001% +5.4% +0.1%
supabase-studio check +1.6% +0.002% +1.0% -0.1%
supabase-studio incremental -0.9% +0.002% -0.3% -0.1%
t3code-server check +0.4% +0.003% -1.1% -0.4%
t3code-server incremental +0.3% +0.001% +0.1% +0.1%
mikro-orm check +0.8% +0.001% -0.5% -0.3%
mikro-orm incremental +4.9% +0.004% -0.7% +0.1%
next-packages-next check +0.1% 0.000% +0.9% +0.3%
next-packages-next incremental -0.2% +0.001% -2.7% 0.0%
next-root check +1.2% -0.001% -2.3% -0.6%
next-root incremental -2.1% -0.003% +1.2% 0.0%
storybook check -0.6% 0.000% +0.3% 0.0%
storybook incremental +1.0% -0.006% +1.2% +0.3%
nuxt check -0.2% +0.002% -5.1% +0.2%
nuxt incremental -0.3% +0.003% +5.9% -0.1%
playwright check -0.4% -0.002% +2.6% +1.6%
playwright incremental -3.7% 0.000% -1.1% +0.3%
drizzle-orm check -0.2% 0.000% -7.2% +1.1%
drizzle-orm incremental +0.4% -0.002% -0.3% -0.1%
typeorm check -3.1% +0.002% +4.5% +0.4%
typeorm incremental -1.2% -0.002% -5.5% +0.1%
date-fns check +2.5% +0.018% -5.1% -0.3%
date-fns incremental -0.1% +0.004% -6.2% 0.0%

Negative means the PR used less; positive means it used more. Deltas are medians of paired PR/main ratios for wall time and instructions. Single-threaded runs reduce scheduling noise; shared CI machines can still add noise to wall time.

Measured medians (main → PR)
Project Mode Single-thread wall time (s) Single-thread instructions Default wall time (s) Default peak RSS (MiB)
vscode check 13.793 → 12.690 82,878,212,513.5 → 82,878,087,274 2.152 → 2.062 1872.2 → 1870.7
vscode incremental 9.195 → 9.405 84,788,818,885 → 84,789,603,886 1.692 → 1.680 2193.1 → 2194.8
xstate-main check 0.526 → 0.522 5,578,242,777 → 5,578,329,406 0.129 → 0.129 243.7 → 243.3
xstate-main incremental 0.939 → 0.924 5,730,176,139 → 5,730,132,982.5 0.265 → 0.265 244.8 → 245.1
webpack check 1.674 → 1.663 10,965,153,038 → 10,965,213,166 0.330 → 0.331 407.8 → 406.3
webpack incremental 1.254 → 1.225 11,118,190,771.5 → 11,117,938,699.5 0.307 → 0.290 406.4 → 406.5
mui-docs check 2.903 → 2.793 33,289,397,861 → 33,289,107,007.5 1.105 → 1.074 1250.1 → 1245.8
mui-docs incremental 3.034 → 2.978 34,557,175,616.5 → 34,560,433,191 1.213 → 1.248 1172.4 → 1176.8
Compiler check 0.221 → 0.211 1,779,240,216 → 1,779,242,374.5 0.096 → 0.094 77.0 → 77.5
Compiler incremental 0.180 → 0.177 1,785,625,436 → 1,785,624,697 0.073 → 0.077 80.1 → 80.2
Compiler-Unions check 0.336 → 0.320 3,059,854,730.5 → 3,059,828,532.5 0.189 → 0.193 80.4 → 80.2
Compiler-Unions incremental 0.234 → 0.237 3,065,267,949 → 3,065,269,277.5 0.106 → 0.104 84.3 → 84.5
cal-diy check 3.608 → 3.582 29,054,689,443.5 → 29,054,201,117.5 0.932 → 0.923 1370.2 → 1373.7
cal-diy incremental 2.775 → 2.742 30,550,487,704.5 → 30,549,095,883.5 1.034 → 1.034 1280.2 → 1280.9
formbricks-web check 5.388 → 5.623 37,231,409,172.5 → 37,230,746,535.5 1.589 → 1.569 1596.3 → 1596.2
formbricks-web incremental 5.927 → 5.917 39,689,482,992 → 39,689,974,147.5 1.718 → 1.812 1636.2 → 1637.6
supabase-studio check 4.177 → 4.206 40,962,309,437 → 40,963,166,890.5 0.953 → 0.957 1326.5 → 1325.6
supabase-studio incremental 5.598 → 5.539 43,807,662,768.5 → 43,808,187,215.5 1.595 → 1.597 1381.7 → 1380.4
t3code-server check 5.294 → 5.334 41,210,349,866.5 → 41,211,624,859.5 1.954 → 1.968 1472.7 → 1467.3
t3code-server incremental 3.900 → 3.966 41,612,457,869.5 → 41,612,674,111.5 1.508 → 1.531 1321.4 → 1322.2
mikro-orm check 4.485 → 4.519 50,624,644,827.5 → 50,624,998,424.5 1.022 → 0.999 1545.8 → 1541.1
mikro-orm incremental 7.440 → 7.745 50,851,891,721 → 50,853,519,420 1.948 → 1.895 1494.8 → 1495.5
next-packages-next check 1.468 → 1.474 17,461,364,980.5 → 17,461,305,855.5 0.371 → 0.368 561.2 → 562.8
next-packages-next incremental 1.879 → 1.864 17,743,772,413 → 17,743,937,528.5 0.524 → 0.509 565.9 → 565.9
next-root check 1.453 → 1.464 14,014,442,165 → 14,014,189,633 0.285 → 0.281 437.6 → 435.1
next-root incremental 1.518 → 1.579 14,388,153,028.5 → 14,387,887,535.5 0.394 → 0.404 475.5 → 475.5
storybook check 0.855 → 0.851 9,068,696,181 → 9,068,852,791 0.222 → 0.224 412.2 → 412.2
storybook incremental 0.888 → 0.894 9,373,744,651 → 9,373,485,815 0.270 → 0.278 386.5 → 387.7
nuxt check 1.053 → 1.058 8,537,306,037 → 8,537,491,147.5 0.256 → 0.245 394.3 → 395.3
nuxt incremental 0.936 → 0.936 8,915,284,487.5 → 8,915,521,268 0.233 → 0.248 395.2 → 394.8
playwright check 0.822 → 0.830 7,457,827,653 → 7,457,674,218 0.200 → 0.201 364.7 → 370.4
playwright incremental 1.452 → 1.462 7,591,287,242 → 7,591,286,080 0.397 → 0.377 343.2 → 344.1
drizzle-orm check 0.606 → 0.604 5,978,922,557 → 5,978,897,906 0.209 → 0.194 379.6 → 383.9
drizzle-orm incremental 0.529 → 0.530 6,143,702,012 → 6,143,712,654.5 0.183 → 0.180 348.0 → 347.7
typeorm check 0.723 → 0.688 6,418,709,822.5 → 6,418,797,528 0.145 → 0.151 227.1 → 228.0
typeorm incremental 0.893 → 0.859 6,736,973,691.5 → 6,736,960,551 0.229 → 0.225 233.5 → 233.8
date-fns check 0.364 → 0.377 3,354,385,746.5 → 3,354,929,511 0.125 → 0.124 152.2 → 151.8
date-fns incremental 0.336 → 0.333 3,570,179,906.5 → 3,570,379,202.5 0.169 → 0.166 163.4 → 163.4

@maschwenk
maschwenk marked this pull request as ready for review October 28, 2026 13:42
@maschwenk

maschwenk commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

@Boshen small leak fix for

ready for a look

@Boshen
Boshen added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 6d0c725 Oct 29, 2026
115 checks passed
@Boshen
Boshen deleted the max/lsp-session-weak-client branch October 29, 2026 09:59
arkadia-agents Bot pushed a commit to arkadia-so/tsrs that referenced this pull request Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants