AFAIK V8 has a known hard limit on the length of allowed String
s. Trying to parse >500MB Strings will pop the error:
Invalid String Length
Using V8 flags to increase the heap size doesn't make any difference
$ node --max_old_space_size=5000 process-large-string.js
I know that I should be using Streams instead. However is there any way to increase the maximum allowed String
length anyway?
Update: Answer from @PaulIrish below indicates they upped it to 1GB - but it's still not user-configurable
While an individual quoted string cannot be longer than 2048 bytes, a string literal of roughly 65535 bytes can be constructed by concatenating strings.
The language specification requires strings to have a maximum length of 253 - 1 elements, which is the upper limit for precise integers.
The most straightforward is fs. readFile() wherein, the whole file is read into memory and then acted upon once Node has read it, and the second option is fs. createReadStream() , which streams the data in (and out) similar to other languages like Python and Java.
Node 6 uses V8 release 5 as its JavaScript engine. (The first few point releases of Node 8 also use V8 release 5, but they use a newer V8 point release than Node 6 did.)
In summer 2017, V8 increased the maximum size of strings from ~256MB to ~1GB. Specifically, from 2^28 - 16
to 2^30 - 25
on 64-bit platforms. V8 ticket.
This change landed in:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With