11

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

2 Answers 2

16

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
Sign up to request clarification or add additional context in comments.

1 Comment

This appears to have regressed back tp 2^28 due to pointer compression and recently bumped back up to 2^29 (0.5GB) as per github.com/v8/v8/commit/… :(
14

Sorry, no, there is no way to increase the maximum allowed String length.

It is hard-coded in the source, and a lot of code implicitly relies on it, so while allowing larger strings is known to be on people's wishlist, it is going to be a lot of work and won't happen in the near future.

4 Comments

Do you happen to know the reason for this limitation? Why does String have that particular max length in V8?
It dates back all the way to 2010. Back then, 512MB was the overall heap limit, and I guess it was a no-brainer to decide that no single string could/should be bigger than the heap ;-) (512 MB = memory consumption of a UTF-16 string with length 2^28.)
This is no longer the case. See my answer.
@PaulIrish well , it actually still IS the case that there is a maximum limit; the limit was increased to roughly 1gig

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.