Do common JavaScript engines, such as V8 and WebKit's JavaScriptCore, use string interning for JavaScript strings? Or do they actually keep multiple instances of identical strings in memory?
|
Yes. In general any literal string, identifier, or other constant string in JS source is interned. However implementation details (exactly what is interned for instance) varies, as well as when the interning occurs. Note that a string value is not the same as a String Object though, String Objects are not interned because that would be fundamentally incorrect behaviour. |
|||||||||||||||||||||
|
http://jsperf.com/strinterning Yes in Chrome, no in Aurora 15 and FF 13! Comparing two strings is 85% slower than comparing two pointers in Firefox. However it's the same speed in Chrome, which is an indication that it is comparing two pointers. Maybe the JS engine team at Mozilla should check their code... |
|||||
|