You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
perf(wsl): return orcad's startup compile memory with a malloc mmap threshold - #34187
When Orca's server inside WSL starts up, it uses about 70 MB of temporary memory to prepare its code. It then frees that memory, but Linux's memory allocator keeps hold of it. Starting the server with one allocator setting makes that memory go back to the system. Users' own shells and tools never see the setting.
What Changed
Launch: when the desktop launches its own build of orcad in a WSL distro, it adds two variables:
GLIBC_TUNABLES=glibc.malloc.mmap_threshold=16384;
a marker, ORCA_HOST_MALLOC_TUNABLES, carrying the same value.
This goes through the existing WSL-only orcadLaunchEnv hook, which now receives the launched slot's version. withOwnBuildLaunchEnv adds the variables only when that version equals this desktop's own orcad build. An older slot, which wouldn't know to remove them, never gets them.
Claim at startup: orcad's and the daemon's entries import a claim module before anything else. If the marker is present and GLIBC_TUNABLES still equals it, both are removed from process.env. glibc reads them only at exec, so removing them doesn't undo the effect.
Daemon: orcad hands the claimed value explicitly to the daemon it spawns, on both the systemd-scope and the direct path. The daemon claims it the same way.
What children see: PTY shells, agents, git and anything else either process starts inherit nothing. A GLIBC_TUNABLES the user set themselves is never touched.
Why
I profiled orcad and its daemon on Linux (linux-arm64 container, pinned Node 24.22.1, managed launch with a warm compile cache; 2 shells and an idle agent-like process; 60 s of idle).
The cause: V8's malloc'd memory peaks at about 101 MB while it compiles the 11 MB orcad bundle, and only about 2 MB of that stays live. glibc keeps the freed space stranded in its main arena. A forced malloc_trim(0) via gdb confirmed it: 279 → 214 MB without the compile cache, 233 → 217 MB with it.
The fix: serving allocations of 16 KB and up from mmap returns the memory when it's freed.
Results on this branch's build, idle RSS in MB:
orcad
daemon
sum
without the launch env (×3: main ×1, this branch ×2)
232–233
79
311
with the launch env (×3)
193
71
264
Flood A/B (300 MB of output through a terminal, two runs each, combined with #2's semi-space change):
wall time
orcad CPU
daemon CPU
default
4.1 s / 5.4 s
6.1 s / 6.5 s
4.1 s / 4.8 s
tuned
4.6 s / 4.1 s
6.5 s / 6.0 s
4.5 s / 4.1 s
The differences are within noise. 60 s after the flood, orcad settles at 300–312 MB against 343 MB by default.
Alternatives I measured and didn't pick:
setting
orcad idle RSS (MB)
mmap_threshold=65536
195
trim_threshold=0
199
arena_max=1
214
MALLOC_ARENA_MAX=2 (awin)
no effect
Node has no API to trim malloc, so setting the variable at launch is the only route.
User-risk: low. Only the orcad and daemon processes of this build's own WSL slot run with a different malloc threshold. User processes keep their environment: on this branch's Linux build, every shell and the agent process showed no GLIBC_TUNABLES in /proc/<pid>/environ. On musl distros glibc tunables don't apply, so nothing changes there.
Flag-off: inert outside WSL. SSH launches never call the WSL hook, the desktop's own daemon never sees the marker, and an older slot isn't given it. Reverting this PR restores today's launch exactly.
Linked Issue
Internal WSL host memory work (D3 bar).
Visual Proof
N/A: no UI change. This changes the server's memory use only.
Testing
host-malloc-tunables.test.ts:
the claim removes what the launch set and keeps it only for the daemon;
a user-set GLIBC_TUNABLES is untouched, including one that replaced the launch's value;
nothing is handed on when the launch set nothing;
orcad's and the daemon's entries import the claim first.
wsl-orcad-own-build-launch-env.test.ts: this build's slot gets it, an older slot doesn't, and nothing is added before the build version is known.
daemon-launched-child-spawn.test.ts: the daemon gets the claimed value on both launch paths, and nothing when unset.
pty-subprocess-env-inheritance.test.ts: after the claim, a PTY shell's env has neither variable.
End to end: this branch's orcad, built for Linux and launched with the env. Shells and the agent process are clean in /proc/<pid>/environ; the daemon received it; RSS is in the table above.
Under the load rule: pnpm tc, pnpm run check:code-quality:changed, and the touched suites (WSL deploy, transport, launch, daemon spawn, PTY env, preflight order) pass. CI runs the full suite.
I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.
Notes
SSH: unchanged. Whether to offer this to SSH hosts is a separate decision.
Desktop: unchanged.
Wire compatibility: none needed. Old orcad never receives the variables; new orcad launched by an older desktop simply runs without them.
Checklist
This PR is small and focused
I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
Before/after screenshots or videos attached for UI changes, or N/A with reason
Self-reviewed for correctness, security, and performance
Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)
…hreshold
V8 frees ~70 MB after compiling orcad's bundle, but glibc keeps it stranded
in the main arena. WSL launches of this build's own slot now set
GLIBC_TUNABLES=glibc.malloc.mmap_threshold=16384; orcad and its daemon
remove it at startup and orcad hands it only to the daemon, so shells,
agents and git keep the user's malloc. Older slots never get it.
The change adds helpers to set and claim host malloc tunables, then passes claimed values into daemon environments. The transport launch callback now receives the launched slot’s full version. A wrapper adds tunables to the launch environment only when that version matches the current build version. Tests cover tunable claiming, daemon and PTY environment behavior, and version matching.
Priority: Low
Merge Risk: Moderate · up to 5eb68
On WSL, a user's existing GLIBC_TUNABLES can be silently replaced and then removed for orcad and the shells and agents it spawns. This affects only users who set that variable in the guest environment. Apply the threshold only when the variable is unset before merging.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surv…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Title check
The title clearly identifies the WSL performance change and the malloc mmap threshold used to return orcad startup memory.
Description check
The description follows the required template and provides clear ELI5, change, rationale, testing, compatibility, and checklist details. The Linked Issue section names internal work but does not provi…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Description check
Explanation
The description follows the required template and provides clear ELI5, change, rationale, testing, compatibility, and checklist details. The Linked Issue section names internal work but does not provide an actual issue reference, and the manual-test and full-command checklist items remain unchecked.
Full details: Docstring Coverage
Explanation
Docstring coverage is 44.44% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 9 functions across 14 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches: 💡 1
📝 Generate docstrings: 💡
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
The reason will be displayed to describe this comment to others. Learn more.
Minor · Maintainability & Code Quality · Quick win
Supported by static analysis
Script executed:
sed -n 300,345p src/main/daemon/pty-subprocess-env-inheritance.test.ts
Repository: stablyai/orca
Length of output: 1726
Restore pre-existing malloc environment values.
If the test process already has GLIBC_TUNABLES or the marker variable, the finally block deletes that value and leaks a changed environment to later tests. Save each original value before assigning the launch environment, then restore it explicitly in finally.
set -o pipefail
printf'%s\n''--- WSL deployment and transport ---'
sed -n '1,190p' src/main/wsl/wsl-orcad-deploy.ts
sed -n '1,180p' src/main/wsl/wsl-orcad-host-transport.ts
printf'%s\n''--- runtime control launch binding ---'
sed -n '90,160p' src/main/managed-server/install/orcad-remote-runtime-control.ts
printf'%s\n''--- WSL command runner ---'
sed -n '1,130p' src/main/wsl/wsl-command-loop.ts
rg -n -F --glob '*.ts' -e 'loginPath:' -e 'runWsl' -e 'wslCommand' -e 'execFile' src/main/wsl src/main/managed-server src/main/ssh ||test"$?" -eq 1
Repository: stablyai/orca
Length of output: 37695
Preserve an inherited GLIBC_TUNABLES.
The WSL path starts sh -c directly, so this source does not establish that a login profile runs. However, any GLIBC_TUNABLES already present in the guest environment is still overwritten by the matching own-build launch assignment. claimHostMallocTunables then removes that value before child processes inherit the environment.
Apply the threshold only when the guest variable is unset, and add the claim marker only when this launch injected the value. Carrying the value through claimHostMallocTunables cannot recover it after the launch assignment overwrites it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ELI5
When Orca's server inside WSL starts up, it uses about 70 MB of temporary memory to prepare its code. It then frees that memory, but Linux's memory allocator keeps hold of it. Starting the server with one allocator setting makes that memory go back to the system. Users' own shells and tools never see the setting.
What Changed
Launch: when the desktop launches its own build of orcad in a WSL distro, it adds two variables:
GLIBC_TUNABLES=glibc.malloc.mmap_threshold=16384;ORCA_HOST_MALLOC_TUNABLES, carrying the same value.This goes through the existing WSL-only
orcadLaunchEnvhook, which now receives the launched slot's version.withOwnBuildLaunchEnvadds the variables only when that version equals this desktop's own orcad build. An older slot, which wouldn't know to remove them, never gets them.Claim at startup: orcad's and the daemon's entries import a claim module before anything else. If the marker is present and
GLIBC_TUNABLESstill equals it, both are removed fromprocess.env. glibc reads them only at exec, so removing them doesn't undo the effect.Daemon: orcad hands the claimed value explicitly to the daemon it spawns, on both the systemd-scope and the direct path. The daemon claims it the same way.
What children see: PTY shells, agents, git and anything else either process starts inherit nothing. A
GLIBC_TUNABLESthe user set themselves is never touched.Why
I profiled orcad and its daemon on Linux (linux-arm64 container, pinned Node 24.22.1, managed launch with a warm compile cache; 2 shells and an idle agent-like process; 60 s of idle).
malloc_trim(0)via gdb confirmed it: 279 → 214 MB without the compile cache, 233 → 217 MB with it.Results on this branch's build, idle RSS in MB:
Flood A/B (300 MB of output through a terminal, two runs each, combined with #2's semi-space change):
The differences are within noise. 60 s after the flood, orcad settles at 300–312 MB against 343 MB by default.
Alternatives I measured and didn't pick:
mmap_threshold=65536trim_threshold=0arena_max=1MALLOC_ARENA_MAX=2(awin)Node has no API to trim malloc, so setting the variable at launch is the only route.
User-risk: low. Only the orcad and daemon processes of this build's own WSL slot run with a different malloc threshold. User processes keep their environment: on this branch's Linux build, every shell and the agent process showed no
GLIBC_TUNABLESin/proc/<pid>/environ. On musl distros glibc tunables don't apply, so nothing changes there.Flag-off: inert outside WSL. SSH launches never call the WSL hook, the desktop's own daemon never sees the marker, and an older slot isn't given it. Reverting this PR restores today's launch exactly.
Linked Issue
Internal WSL host memory work (D3 bar).
Visual Proof
N/A: no UI change. This changes the server's memory use only.
Testing
host-malloc-tunables.test.ts:GLIBC_TUNABLESis untouched, including one that replaced the launch's value;wsl-orcad-own-build-launch-env.test.ts: this build's slot gets it, an older slot doesn't, and nothing is added before the build version is known.daemon-launched-child-spawn.test.ts: the daemon gets the claimed value on both launch paths, and nothing when unset.pty-subprocess-env-inheritance.test.ts: after the claim, a PTY shell's env has neither variable.End to end: this branch's orcad, built for Linux and launched with the env. Shells and the agent process are clean in
/proc/<pid>/environ; the daemon received it; RSS is in the table above.Under the load rule:
pnpm tc,pnpm run check:code-quality:changed, and the touched suites (WSL deploy, transport, launch, daemon spawn, PTY env, preflight order) pass. CI runs the full suite.I manually tested these changes locally
Automated tests added/updated, or explained why not below
AI Disclosure
Review
Agent skill upstream boundary
Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)