`
鹤惊昆仑
  • 浏览: 230272 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

为什么safari浏览器新的js引擎squirrelfish非常快

阅读更多
announcing-squirrelfish
引用

Why It’s Fast
Like the interpreters for many scripting languages, WebKit’s previous JavaScript interpreter was a simple syntax tree walker. To execute a program, it would first parse the program into a tree of statements and expressions. For example, the expression “x + y” might parse to

        +
      /   \
     x     y
Having created a syntax tree, the interpreter would recursively visit the nodes in the tree, performing their operations and propagating execution state. This execution model incurred a few types of run-time cost.

  • First, a syntax tree describes a program’s grammatical structure, not the operations needed to execute it. Therefore, during execution, the interpreter would repeatedly visit nodes that did no useful work. For example, for the block “{ x++; }”, the interpreter would first visit the block node “{…}”, which did nothing, and then visit its first child, the increment node “x++”, which incremented x.
  • Second, even nodes that did useful work were expensive to visit. Each visit required a virtual function call and return, which meant a couple of indirect memory reads to retrieve the function being called, and two indirect branches—one for the call, and one for the return. On modern hardware, “indirect” is a synonym for “slow”, since indirection tends to defeat caching and branch prediction.
  • Third, to propagate execution state between nodes, the interpreter had to pass around a bunch of data. For example, when processing a subtree involving a local variable, the interpreter would copy the variable’s value between all the nodes in the subtree. So, starting at the “x” part of the expression “f((x) + 1)”, a variable node “x” would return x to a parentheses node “(x)”, which would return x to a plus node “(x) + 1”. Then, the plus node would return (x) + 1 to an argument list node “((x) + 1)”, which would copy that value into an argument list object, which, in turn, it would pass to the function node for f. Sheesh!


In our first rounds of optimization, we squeezed out as much performance as we could without changing this underlying architecture. Doing so allowed us to regression test each optimization we wrote. It also set a very high bar for any replacement technology. Finally, having realized the full potential of the syntax tree architecture, we switched to bytecode.

SquirrelFish’s bytecode engine elegantly eliminates almost all of the overhead of a tree-walking interpreter. First, a bytecode stream exactly describes the operations needed to execute a program. Compiling to bytecode implicitly strips away irrelevant grammatical structure. Second, a bytecode dispatch is a single direct memory read, followed by a single indirect branch. Therefore, executing a bytecode instruction is much faster than visiting a syntax tree node. Third, with the syntax tree gone, the interpreter no longer needs to propagate execution state between syntax tree nodes.

The bytecode’s register representation and calling convention work together to produce other speedups, as well. For example, jumping to the first instruction in a JavaScript function, which used to require two C++ function calls, one of them virtual, now requires just a single bytecode dispatch. At the same time, the bytecode compiler, which knows how to strip away many forms of intermediate copying, can often arrange to pass arguments to a JavaScript function without any copying.


squirrelfish-bytecode
分享到:
评论

相关推荐

    多浏览器的单元测试工具 多浏览器集成的JavaScript单元测试工县 共28页.pdf

    对于JavaScript,由于其在不同浏览器中可能存在兼容性问题,因此进行多浏览器的单元测试显得尤为重要。本文将探讨如何集成多浏览器的JavaScript单元测试工具,以确保代码在多种浏览器环境下都能正常工作。 **选择...

    JavaScript语言教程:JavaScript简单介绍

    - **最初的命名**:JavaScript最初被命名为“LiveScript”,但由于Java语言在当时的流行度非常高,因此将其重新命名为JavaScript,旨在借助Java的名气来推广这门新语言。 - **ECMAScript规范**:随着JavaScript的...

    Knowledge-Map:知识图

    名词引擎,编译器与作用域浏览器不同,其引擎也不同,例如Chrome采用的是v8,Safari采用的是SquirrelFish Extreme。编译器:编译过程主要分为“词法分析”,“语法分析”和“代码生成”。作用域(范围):根据名称...

    在JavaScript中,为什么要尽可能使用局部变量?

    Opera在某些情况下表现优于这些浏览器,但仍然不及基于V8和SquirrelFish的引擎。 总的来说,使用局部变量可以减少标识符解析的复杂度,提高代码执行效率。这不仅适用于变量的读取,也适用于变量的写入操作。此外,...

    Android SDK1.5新视角 (介绍AndroidSDK1.5新特性)

    内置的Chromelite浏览器在Android 1.5中采用了最新的Webkit引擎和Squirrelfish JavaScript引擎,网页加载速度更快,浏览体验更佳。此外,还新增了网页内容复制、页内搜索功能,以及对网页默认编码的自定义设置。这些...

    完整版《HTML5高级程序设计》2

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 20 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24 2.1.5 ...

    完整版《HTML5高级程序设计》4

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 20 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24 2.1.5 ...

    完整版《HTML5高级程序设计》5

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 20 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24 2.1.5 ...

    完整版《HTML5高级程序设计》3

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 20 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24 2.1.5 ...

    HTML5高级程序设计

    1.6.8 monkeys、squirrelfish和其他javascript引擎 19 1.7 小结 20 .第2章 canvas api 22 2.1 html5 canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24...

    HTML5高级程序设计.part5

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 20 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24 ...

    HTML5高级程序设计.part4

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 20 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24 ...

    HTML5高级程序设计.part1

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 20 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24 ...

    HTML5高级程序设计.part2

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 20 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24 ...

    HTML5高级程序设计.part3

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 20 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 24 ...

    javascript 用局部变量来代替全局变量第1/2页

    然而,随着Google Chrome和WebKit午夜版等新浏览器的出现,采用优化后的JavaScript引擎(如V8和SquirrelFish)之后,访问变量时即使作用域链深度增加,性能也不会明显下降。这些优化包括改进标识符解析过程,从而...

    HTML5程序设计(第2版).[荷]Peter Lubbers(带详细书签).pdf

    1.6.8 Monkeys、Squirrelfish和其他JavaScript引擎 19 1.7 小结 21 第2章 Canvas API 22 2.1 HTML5 Canvas概述 22 2.1.1 历史 22 2.1.2 canvas是什么 23 2.1.3 canvas坐标 23 2.1.4 什么情况下不用canvas 23 ...

    android 源码结构

    8. **external**:集成的开源软件组件,如Webkit、SquirrelFish等。 9. **frameworks**:核心框架的代码,包括Java和C++两部分,提供了应用程序运行所需的基本服务和API。 10. **hardware**:硬件抽象层(HAL),...

Global site tag (gtag.js) - Google Analytics