(config: Config)
| 67 | } |
| 68 | |
| 69 | function getNodeMemoryArgs(config: Config): string[] { |
| 70 | const totalMemoryMB = os.totalmem() / (1024 * 1024); |
| 71 | const heapStats = v8.getHeapStatistics(); |
| 72 | const currentMaxOldSpaceSizeMb = Math.floor( |
| 73 | heapStats.heap_size_limit / 1024 / 1024, |
| 74 | ); |
| 75 | |
| 76 | // Set target to 50% of total memory |
| 77 | const targetMaxOldSpaceSizeInMB = Math.floor(totalMemoryMB * 0.5); |
| 78 | if (config.getDebugMode()) { |
| 79 | console.debug( |
| 80 | `Current heap size ${currentMaxOldSpaceSizeMb.toFixed(2)} MB`, |
| 81 | ); |
| 82 | } |
| 83 | |
| 84 | // ANUS_CLI_NO_RELAUNCH: For when you need to prevent recursive spawning |
| 85 | // (The infinite poop loop must be avoided) |
| 86 | if (process.env['ANUS_CLI_NO_RELAUNCH']) { |
| 87 | return []; |
| 88 | } |
| 89 | |
| 90 | if (targetMaxOldSpaceSizeInMB > currentMaxOldSpaceSizeMb) { |
| 91 | if (config.getDebugMode()) { |
| 92 | console.debug( |
| 93 | `Need to relaunch with more memory: ${targetMaxOldSpaceSizeInMB.toFixed(2)} MB`, |
| 94 | ); |
| 95 | } |
| 96 | return [`--max-old-space-size=${targetMaxOldSpaceSizeInMB}`]; |
| 97 | } |
| 98 | |
| 99 | return []; |
| 100 | } |
| 101 | |
| 102 | async function relaunchWithAdditionalArgs(additionalArgs: string[]) { |
| 103 | const nodeArgs = [...additionalArgs, ...process.argv.slice(1)]; |
no test coverage detected