5 ms·
I'll add something: if a string [^1] contains essentially only ASCII [^2] characters v8 will use 1 byte per character, if that string contains _any_ character o
by fabiospampinato 6y ago
I'll add something: if a string [^1] contains essentially only ASCII [^2] characters v8 will use 1 byte per character, if that string contains _any_ character other than ASCII characters in it then it will use 2 bytes for each character in the string. Said it differently storing strings as lines may save you up to 50% of memory usage depending on your use case.
[^1]: It actually depends on how that string was made, if internally it still references the parent string then slicing it up into lines won't save you any memory. I'm referring to "flattened" strings.
[^2]: I don't remember what the exact character set is, I think it's not exactly ASCII but close enough.
- esprehn 6y agoIt's latin1. The same is true of DOM strings in Chromium, like attributes, blocks of text, and inline scripts. Webkit and the JDK implement the same string optimization, while .NET unfortunately doesn't: https://github.com/dotnet/runtime/issues/6612 https://github.com/dotnet/runtime/issues/6612
- davethedevguy 6y agoI didn't know that! I'll add something to the post. Thank you!
- faitswulff 6y agoRegarding [^2], is it code page 437 by any chance? https://en.m.wikipedia.org/wiki/Code_page_437 https://en.m.wikipedia.org/wiki/Code_page_437
- esprehn 6y agoIt's Latin1 which I think is code page 850: https://en.m.wikipedia.org/wiki/Code_page_850 https://en.m.wikipedia.org/wiki/Code_page_850