Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If someone could answer me this it would be much appreciated: The blogpost describes the current flow of code as such: Interpreter -> JaegerMonkey -> IonMonkey

Is process repeated every time I open a website or do browsers cache the generated bytecode? What about popular libraries? Will jQuery get JITed differently for every website that has it?



There will be separate jitcode generated for each page. It's hard to share this kind of code because during generation we often bake-in immediate pointers to various things (like global objects, etc.) into the generated jitcode.

The jitcode itself isn't that big of a memory issue, though. The collected type info is more heavyweight, but that's really hard to share across different pages. There are security concerns, concurrency concerns, and just complexity.


Also, the generated JIT code isn't static and does not simply map source to native like in statically compiled languages. A lot of JS JITs, including Firefox'es, dynamically rewrite the emitted code as it executes to add support for newly-seen types. So not only will the code be different environment to environment, it will also be different within the same script execution.


Would the same library generate the same jitcode on different websites? Does how the library is used account for this. At a high level, if I never used jQuery animation code on my site, but another site does, with the same jQuery version, would the jitcode for my site have removed the unnecessary animation stuff?


> Would the same library generate the same jitcode on different websites?

No. The jitcode is specialized based on actual observed types, so depending on how you call the methods you get different jitcode.


And do you cache jitcode of the same page between different visits?


No. We however had several ideas over the years to cache bytecode together with the JavaScript code. But that never really went anywhere. Caching JIT-code is difficult, because addresses (like jumps) change unless you malloc at the exact same location or manually fix up everything.


It sounds like you need two separate JITcode phases: first, generate Position-Independent JITcode (and cache that); then for each script that requires it, load it and "link" it.


I see. I was thinking in something more bytecode-like, didn't knew that jitcode has direct adressess in it.


How much worse peformance-wise would generating PIC be to address this?


If a page goes into the back/forward cache, then its js code generally gets kept around. But we don't persistently store jitcode for a page, and I don't know of any JS engine that does.


More sharing would be great for memory consumption, but it's really hard. See https://bugzilla.mozilla.org/show_bug.cgi?id=846173 for an interesting example.


Also different sites use different versions of jQuery




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: