Merged
feat(cli): 堆阈值/re-exec/memoryCache 支持环境变量配置(CPTF_HEAP_THRESHOLD/CPTF_MAX_OLD_SPACE/CPTF_TS_NODE_MEMORY_CACHE),默认与上游一致,16GB Mac 可降低规避 jetsam #13
liu_wentaoAdd on Aug 28
feat(cli): 堆阈值/re-exec/memoryCache 支持环境变量配置(CPTF_HEAP_THRESHOLD/CPTF_MAX_OLD_SPACE/CPTF_TS_NODE_MEMORY_CACHE),默认与上游一致,16GB Mac 可降低规避 jetsam #13
Merged
Total: 2 files changed+9-2
| @@ -7,13 +7,19 @@ | |||
| 7 | // step files × full UI element trees can exceed the default 4GB limit). | 7 | // step files × full UI element trees can exceed the default 4GB limit). |
| 8 | // Only re-exec for the heavy commands (run/compare); lightweight commands | 8 | // Only re-exec for the heavy commands (run/compare); lightweight commands |
| 9 | // (devices/scan/index/...) pay no double Node startup cost. | 9 | // (devices/scan/index/...) pay no double Node startup cost. |
| 10 | +// | ||
| 11 | +// Configurable via env (defaults preserve upstream behavior): | ||
| 12 | +// CPTF_HEAP_THRESHOLD heap threshold in GB to trigger re-exec (default 8) | ||
| 13 | +// CPTF_MAX_OLD_SPACE re-exec --max-old-space-size in MB (default 16384) | ||
| 10 | const HEAVY_COMMANDS = ['run', 'compare']; | 14 | const HEAVY_COMMANDS = ['run', 'compare']; |
| 11 | const firstArg = process.argv[2]; | 15 | const firstArg = process.argv[2]; |
| 12 | if (HEAVY_COMMANDS.includes(firstArg)) { | 16 | if (HEAVY_COMMANDS.includes(firstArg)) { |
| 13 | try { | 17 | try { |
| 14 | const v8 = require('v8'); | 18 | const v8 = require('v8'); |
| 15 | const stats = v8.getHeapStatistics(); | 19 | const stats = v8.getHeapStatistics(); |
| 16 | - if (stats.heap_size_limit < 8 * 1024 * 1024 * 1024) { | 20 | + const thresholdGB = parseInt(process.env.CPTF_HEAP_THRESHOLD || '8', 10); |
| 21 | + const maxOldSpace = process.env.CPTF_MAX_OLD_SPACE || '16384'; | ||
| 22 | + if (stats.heap_size_limit < thresholdGB * 1024 * 1024 * 1024) { | ||
| 17 | let signalCount = 0; | 23 | let signalCount = 0; |
| 18 | const stayAlive = () => { | 24 | const stayAlive = () => { |
| 19 | signalCount++; | 25 | signalCount++; |
| @@ -25,7 +31,7 @@ if (HEAVY_COMMANDS.includes(firstArg)) { | |||
| 25 | process.on('SIGTERM', stayAlive); | 31 | process.on('SIGTERM', stayAlive); |
| 26 | try { | 32 | try { |
| 27 | require('child_process').execFileSync(process.argv[0], [ | 33 | require('child_process').execFileSync(process.argv[0], [ |
| 28 | - '--max-old-space-size=16384', | 34 | + `--max-old-space-size=${maxOldSpace}`, |
| 29 | '--max-semi-space-size=256', | 35 | '--max-semi-space-size=256', |
| 30 | '--expose-gc', | 36 | '--expose-gc', |
| 31 | ...process.argv.slice(1), | 37 | ...process.argv.slice(1), |
| @@ -10,6 +10,7 @@ export function registerTsNode(logger?: Logger): void { | |||
| 10 | try { | 10 | try { |
| 11 | require('ts-node').register({ | 11 | require('ts-node').register({ |
| 12 | transpileOnly: true, | 12 | transpileOnly: true, |
| 13 | + ...(process.env.CPTF_TS_NODE_MEMORY_CACHE === 'false' ? { memoryCache: false } : {}), | ||
| 13 | compilerOptions: { | 14 | compilerOptions: { |
| 14 | module: 'commonjs', | 15 | module: 'commonjs', |
| 15 | target: 'ES2020', | 16 | target: 'ES2020', |