Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 62d2cd4

Browse filesBrowse files
tannaladuh95
authored andcommitted
cli: add --max-heap-size option
PR-URL: #58708 Reviewed-By: Gürgün Dayıoğlu <hey@gurgun.day>
1 parent 872d159 commit 62d2cd4
Copy full SHA for 62d2cd4

3 files changed

+57Lines changed: 57 additions & 0 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/cli.md‎

Copy file name to clipboardExpand all lines: doc/api/cli.md
+7Lines changed: 7 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -3741,6 +3741,7 @@ V8 options that are allowed are:
37413741
* `--expose-gc`
37423742
* `--interpreted-frames-native-stack`
37433743
* `--jitless`
3744+
* `--max-heap-size`
37443745
* `--max-old-space-size`
37453746
* `--max-semi-space-size`
37463747
* `--perf-basic-prof-only-functions`
@@ -4099,6 +4100,12 @@ documented here:
40994100

41004101
### `--jitless`
41014102

4103+
### `--max-heap-size`
4104+
4105+
Specifies the maximum heap size (in megabytes) for the process.
4106+
4107+
This option is typically used to limit the amount of memory the process can use for its JavaScript heap.
4108+
41024109
<!-- Anchor to make sure old links find a target -->
41034110

41044111
<a id="--max-old-space-sizesize-in-megabytes"></a>
Collapse file

‎src/node_options.cc‎

Copy file name to clipboardExpand all lines: src/node_options.cc
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
12281228
"help system profilers to translate JavaScript interpreted frames",
12291229
V8Option{},
12301230
kAllowedInEnvvar);
1231+
AddOption("--max-heap-size", "", V8Option{}, kAllowedInEnvvar);
12311232
AddOption("--max-old-space-size", "", V8Option{}, kAllowedInEnvvar);
12321233
AddOption("--max-old-space-size-percentage",
12331234
"set V8's max old space size as a percentage of available memory "
Collapse file
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const { spawnSync } = require('child_process');
5+
const path = require('path');
6+
const fs = require('fs');
7+
const tmpdir = require('./tmpdir');
8+
9+
const testScript = `
10+
const v8 = require('v8');
11+
const stats = v8.getHeapStatistics();
12+
const maxHeapSizeMB = Math.round(stats.heap_size_limit / 1024 / 1024);
13+
console.log(maxHeapSizeMB);
14+
`;
15+
16+
tmpdir.refresh();
17+
const scriptPath = path.join(tmpdir.path, 'heap-limit-test.js');
18+
fs.writeFileSync(scriptPath, testScript);
19+
20+
const child = spawnSync(
21+
process.execPath,
22+
[scriptPath],
23+
{
24+
encoding: 'utf8',
25+
env: {
26+
...process.env,
27+
NODE_OPTIONS: '--max-heap-size=750',
28+
},
29+
},
30+
);
31+
32+
assert.strictEqual(
33+
child.status,
34+
0,
35+
[
36+
`Child process did not exit cleanly.`,
37+
` Exit code: ${child.status}`,
38+
child.stderr ? ` Stderr: ${child.stderr.toString()}` : '',
39+
child.stdout ? ` Stdout: ${child.stdout.toString()}` : '',
40+
].filter(Boolean).join('\n'),
41+
);
42+
const output = child.stdout.trim();
43+
const heapLimit = Number(output);
44+
45+
assert.strictEqual(
46+
heapLimit,
47+
750,
48+
`max heap size is ${heapLimit}MB, expected 750MB`,
49+
);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.