Friday, 3 January 2020

If a similar string is stored several times, does each of them use the same amount of memory, or can v8 optimize this in any way?

Not entirely sure how to properly phrase the question in the title, but I can give you an example.I want to store X number of objects that looks like: { type: [ 'foo...' | 'bar...' | 'baz...' ] }X will be in the millions, and I was wondering if v8 would optimize them so that each of 'foo...' doesn't use the same amount of bytes of memory, but only point to the same string literal.I could easily "fix" this by using an integer instead of a string, but I was just wondering how v8/Node actually handle similar strings.

Submitted January 03, 2020 at 09:23AM by freeall

No comments:

Post a Comment