Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

V8/Node.js increase max allowed String length

Tags:

node.js

v8

AFAIK V8 has a known hard limit on the length of allowed Strings. 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

like image 219
nicholaswmin Avatar asked Jun 14 '17 01:06

nicholaswmin


People also ask

Is there a limit to how long a string can be?

While an individual quoted string cannot be longer than 2048 bytes, a string literal of roughly 65535 bytes can be constructed by concatenating strings.

How long can a string be in JS?

The language specification requires strings to have a maximum length of 253 - 1 elements, which is the upper limit for precise integers.

How do I read a large file in node?

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.

What version of V8 does node use?

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.)


1 Answers

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:

  • V8: 6.2.100
  • Chromium: 62.0.3167.0
  • Node.js: 9.0.0
like image 126
Paul Irish Avatar answered Nov 15 '22 07:11

Paul Irish