I have a large json map with around 1 million objects and each object with around 200 key-value pair.
eg. [{key1 : val1, key2 : val2, ...}, {key1 : val3, key2 : val4, ...}]
as you see the keys are getting duplicated here, with each key means a new String object. Is there any alternative way where I can say that all duplicate keys should point to same String object to reduce the memory size of map. With the mentioned stats the browser blows up with more than 1Gb of memory.
as you see the keys are getting duplicated here, with each key means a new String object.
Well, no, they each get a string primitive. Granted it a subtle distinction, but JavaScript has both:
var sp = "primitive";
var so = new String("object");
Is there a String pool concept in JavaScript?
Not in terms of anything external that you can intentionally invoke such as Java's intern
.
A given JavaScript engine (V8, SpiderMonkey, etc.) may or may not reuse string primitives under the covers as an optimization; it can because strings are immutable in JavaScript, but whether it's ever made it to the top of a development priority list...
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