Faster JavaScript parsing
blog.mozilla.com
blog.mozilla.com
Last I profiled, something like 30% of the pageload time for gmail in Firefox was parsing the JS.
Except they're not. There's a ton of ISO-8859-1 out there, as well as Big5, Shift_JIS, and so forth.
So Gecko canonicalizes all input to a single encoding; that happens to be UTF-16 for various historical reasons.
Note, by the way, that since some non-ASCII characters are syntax-special in JavaScript parsing it in UTF-8 may not in fact be simpler to do fast, because locating particular non-ASCII chars in a UTF8 stream is a bit of a PITA.
I also think that for Javascript files, almost all will be ASCII, with some UTF-8, and little else. JSON is of course only allowed to be Unicode, and I suspect that almost all of it is UTF8, although that will not generally hit the Javascript parser I presume (although maybe Gecko also normalises it?).
Locating non ASCII chars obviously is an issue, but no worse than the line feed issue mentioned in the article. Doubling the size of the input is generally a big performance hit that will be much more significant.
Apart from cache locality issues, it's not, really. And for a linear scan like this prefetching does OK.
And yes, Gecko normalizes JSON input to the JS engine.
I don't have numbers, sorry. But yes, UTF-8 would be the other thing to try normalizing to; it has its own benefits and drawbacks when the system is considered as a whole.
This gives up the real world optimisation of starting work on a partially downloaded file on slow network connections.
Even fast internet connections take a while to download 1MB of javascript. Not to mention the majority of internet users on slower connections.
I think this work could be improved to go back to the old behaviour.
This will make JavaScript parsing faster for the vast majority of sites, and for the majority of users.
If you have a single JavaScript file that is 1MB after gzipping, you really should think about modularising your code and lazy-loading the bits that aren't immediately required. See http://ajaxpatterns.org/On-Demand_Javascript
And it turns out that the optimization is overrated, especially for the common case of the 1MB file being in your cache anyway.