qwen-code/scripts/cli-entry.js
jinye a93ec674e9
perf(cli): enable compile cache and defer getCliVersion for serve (#5938)
Enable Node.js compile cache (module.enableCompileCache) in the serve
fast-path so V8 bytecode is cached across daemon restarts. Start
getCliVersion() as a non-blocking promise and resolve it in parallel
with the runtime module loads inside buildRuntime(), removing it from
the pre-listen critical path.
2026-06-27 14:19:29 +00:00

50 lines
1.3 KiB
JavaScript
Executable file

#!/usr/bin/env node
/**
* @license
* Copyright 2025 Qwen Code
* SPDX-License-Identifier: Apache-2.0
*/
/**
* Production bin entry wrapper.
*
* For most commands: launches dist/cli.js with --expose-gc so that
* global.gc() is available for the memory-pressure monitor's critical-tier
* cleanup.
*
* For `qwen serve`: imports cli.js directly in-process, skipping the
* spawnSync overhead (~370ms on EDR-instrumented hosts). The daemon host
* process never calls global.gc() — only its ACP children do, and they
* independently add --expose-gc via spawnChannel.ts.
*/
import module from 'node:module';
import { spawnSync } from 'node:child_process';
import { fileURLToPath, pathToFileURL } from 'node:url';
import { dirname, join } from 'node:path';
const __dirname = dirname(fileURLToPath(import.meta.url));
const cliPath = join(__dirname, '..', 'dist', 'cli.js');
function isServeCommand() {
return process.argv[2] === 'serve';
}
if (isServeCommand()) {
module.enableCompileCache?.();
process.argv[1] = cliPath;
await import(pathToFileURL(cliPath).href);
} else {
const result = spawnSync(
process.execPath,
['--expose-gc', cliPath, ...process.argv.slice(2)],
{ stdio: 'inherit' },
);
if (result.signal) {
process.kill(process.pid, result.signal);
} else {
process.exit(result.status ?? 1);
}
}