Maximum String Length Across Node.js Versions
it decreased in 2020
Apropos of nothing, Node changed its maximum string length from about 1GB to about 0.5 GB between Node 13 and Node 14. Java would never.
The actual change here is in v8, for example, this commit.
That was generated by this script for Node 8+ and this script for older versions, which include the following vibe-coded binary search.
node --max-old-space-size=8192 -e '
let low=0, high=4*1024*1024*1024, maxLen=0;
while(low<=high) {
const mid=Math.floor((low+high)/2);
try {
const s="x".repeat(mid);
maxLen=mid;
low=mid+1
} catch(e) {
high=mid-1
}
}
console.log(JSON.stringify({
maxLength:maxLen,
v8:process.versions.v8,
node:process.versions.node
}))
'
Results #
| Node Version | V8 Version | Max String Length |
|---|---|---|
| 0.12.18 | 3.28.71.20 | 268,435,440 |
| 4.9.1 | 4.5.103.53 | 268,435,440 |
| 6.17.1 | 5.1.281.111 | 268,435,440 |
| 7.10.1 | 5.5.372.43 | 268,435,440 |
| 8.17.0 | 6.2.414.78 | 1,073,741,799 |
| 9.11.2 | 6.2.414.46-node.23 | 1,073,741,799 |
| 10.24.1 | 6.8.275.32-node.59 | 1,073,741,799 |
| 11.15.0 | 7.0.276.38-node.19 | 1,073,741,799 |
| 12.22.12 | 7.8.279.23-node.57 | 1,073,741,799 |
| 13.14.0 | 7.9.317.25-node.32 | 1,073,741,799 |
| 14.21.3 | 8.4.371.23-node.88 | 536,870,888 |
| 15.14.0 | 8.6.395.17-node.28 | 536,870,888 |
| 16.20.2 | 9.4.146.26-node.26 | 536,870,888 |
| 17.9.1 | 9.6.180.15-node.16 | 536,870,888 |
| 18.20.8 | 10.2.154.26-node.39 | 536,870,888 |
| 19.9.0 | 10.8.168.25-node.16 | 536,870,888 |
| 20.19.5 | 11.3.244.8-node.30 | 536,870,888 |
| 21.7.3 | 11.8.172.17-node.20 | 536,870,888 |
| 22.21.1 | 12.4.254.21-node.33 | 536,870,888 |
| 23.11.1 | 12.9.202.28-node.14 | 536,870,888 |
| 24.11.1 | 13.6.233.10-node.28 | 536,870,888 |
| 25.2.0 | 14.1.146.11-node.13 | 536,870,888 |