Files
orca/config/scripts/dev-rolldown-runtime-env.mjs
T
OrcaWinandOrcaWin 7324dada30 perf(dev): −1.2 GB idle RSS per pnpm dev instance (Rolldown threads + mimalloc purge) (#33836)
* perf(dev): size the dev server's Rolldown runtime for many parallel instances

~93% of idle electron-vite RSS is Rolldown's native mimalloc arenas. The dev
wrapper now gives electron-vite MIMALLOC_PURGE_DELAY=0 and 4 Rolldown/Rayon
threads; a serve-only renderer plugin strips exactly those keys before
Electron spawns, so dev Orca's terminals never inherit them.

* fix(dev): add the runtime-env plugin only when the dev wrapper set its keys

Keeps createDevServeConfig returning the renderer config unchanged when there
is no port and nothing to strip, as electron-vite-output-contract pins.

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-10-26 01:39:36 -07:00

40 lines
1.3 KiB
JavaScript

import os from 'node:os'
export const DEV_RUNTIME_ENV_KEYS = 'ORCA_DEV_RUNTIME_ENV_KEYS'
// Measured idle electron-vite RSS 4.6GB -> 3.0GB with no HMR or startup regression.
const DEV_THREADS = '4'
const DEV_RUNTIME_DEFAULTS = {
// mimalloc otherwise keeps freed Rolldown arenas resident for the whole dev session.
MIMALLOC_PURGE_DELAY: '0',
ROLLDOWN_WORKER_THREADS: DEV_THREADS,
RAYON_NUM_THREADS: DEV_THREADS
}
/** Sizes the dev server's Rolldown runtime; records added keys so Electron's environment can drop them. */
export function withDevRolldownRuntimeEnv(env, availableParallelism = os.availableParallelism()) {
const added = Object.entries(DEV_RUNTIME_DEFAULTS).filter(
([key]) =>
env[key] === undefined &&
(key === 'MIMALLOC_PURGE_DELAY' || availableParallelism > Number(DEV_THREADS))
)
if (added.length === 0) {
return env
}
return {
...env,
...Object.fromEntries(added),
[DEV_RUNTIME_ENV_KEYS]: added.map(([key]) => key).join(',')
}
}
/** Rolldown has read these before the renderer server starts; dev Electron's terminals must not inherit them. */
export function removeDevRolldownRuntimeEnv(env) {
for (const key of (env[DEV_RUNTIME_ENV_KEYS] ?? '').split(',')) {
if (key) {
delete env[key]
}
}
delete env[DEV_RUNTIME_ENV_KEYS]
}