页面加载时,浏览器都会解析Javascript么

这些都是我们已经能够挖掘的细节,值得注意的是,虽然JavaScript通常被认为是虚拟机上进行解释和运行,但这是不是真的直接翻译,往往是直接编译成机器代码(IE除外).

Chrome: V8 Engine

V8引擎含有一个编译缓存,它存储用于编译的JavaScript,这意味着,不管他们是如何被包含,两个相同的源代码将共享一个内存中的缓存,当页面重新加载时缓存不会被清除.
Opera: Carakan Engine
事实上,每当脚本程序进行编译,如果源代码编译结果与最近编译一次结果相同,浏览器将重用从以前的编译结果而完全跳过现在的编译步骤.因此,页面重新加载时JavaScript是在加载缓存,两个相同的脚本的请求不会重新编译.

Firefox: SpiderMonkey Engine

SpiderMonkey的使用Nanojit作为其原生的后端,JIT编译器.在这里可以看到编译的机器代码的过程中,它似乎重新编译加载的脚本.然而,如果我们采用Nanojit仔细窥探其内部,我们看到的更高层次的jstracer,它用来跟踪编译过程,我们可以看到三个阶段的转变:

The trace monitor’s initial state is monitoring. This means that spidermonkey is interpreting bytecode. Every time spidermonkey interprets a backward-jump bytecode, the monitor makes note of the number of times the jump-target program-counter (PC) value has been jumped-to. This number is called the hit count for the PC. If the hit count of a particular PC reaches a threshold value, the target is considered hot.
When the monitor decides a target PC is hot, it looks in a hashtable of fragments to see if there is a fragment holding native code for that target PC. If it finds such a fragment, it transitions to executing mode. Otherwise it transitions to recording mode.

也就是说,热点代码将会缓存,但它没有作出明确的是这些代码在刷新页面后是否保留,但根据Mozilla developer Boris Zbarsky表态,Gecko没有缓存编译过的脚本,但缓存它们是今后努力的方向.

Safari: JavaScriptCore/SquirelFish Engine

We don’t currently cache the bytecode (or the native code). It is an
option we have considered, however, currently, code generation is a
trivial portion of JS execution time (< 2%), so we’re not pursuing
this at the moment.

这是Safari开发主管Maciej Stachowiak写道的,我们有理由相信这点,目前Safari不会缓存字节码.

IE: Chakra Engine

JScript Classic acts like a compiled language in the sense that before any JScript Classic program runs, we fully syntax check the code, generate a full parse tree, and generate a bytecode. We then run the bytecode through a bytecode interpreter. In that sense, JScript is every bit as “compiled” as Java. The difference is that JScript does not allow you to persist or examine our proprietary bytecode. Also, the bytecode is much higher-level than the JVM bytecode — the JScript Classic bytecode language is little more than a linearization of the parse tree, whereas the JVM bytecode is clearly intended to operate on a low-level stack machine.

这是MS JScript开发者在其blog的回复,所以看的出IE也不会缓存字节码,但目前怕一领域没有任何关于IE9 JavaScript引擎的消息,如果有谁知道什么,请发表评论!

发表评论(咦,这里还有个板凳哦!)

设置头像

*

  1. 小冰火人的博客 说:

    在不了解烘焙的人看来,那些自己动手烤面包、蛋糕的人不是无聊,就是矫情,如今满大街都是糕点店,花样又多,价格也不贵,用得着费那个神吗?但在成都有这么一批人,他们在家庭烘焙中找到了乐趣,并把它当做安全健康的时尚生活方式广为传播。那么,好面包去哪儿了?好的面包机去哪儿了?

    东菱 DL-T15B魔法师面包机介绍
    外观:高端设计 质感体现
    1.方形高端彩钢机身
    2.宽阔透明视窗,3.5英寸超大LED显示屏
    技术:专利隐藏式自动撒果料+专利魔法搅拌棒
    1.专利魔法搅拌棒效率提升30%
    2.隐藏式自动撒果料果盒设计
    功能:25+100云菜单
    1. 25种标准菜单、独创大米功能菜单
    2