[资料总结]Safari将开发新的解释器SquirrelFish

来源:互联网 发布:电视看直播软件 编辑:程序博客网 时间:2024/05/01 15:16

       为适应浏览器市场的发展Tamarin系的另一个分支SquirrelFish近期也有不小的动向,下面让我们来看一些资料。

1、新闻背景

上周,WebKit开发团队向外正式宣布他们正在为WebKit的JavaScript引擎开发一个新解释器--SquirrelFish。根据WebKit官方博客,SquirrelFish的速度比之前的解释器快1.6倍”。

与之前的解释器使用遍历语法树的实现方式不同的是,SquirrelFish的实现采用字节码。

遍历语法树实现方式存在的高代价问题,在SquirrelFish字节码引擎中基本都不存在。首先,一个字节码流能够精确描述执行程序所需的操作,编译成字节码实际上隐性地跳过了不相关的语法结构。其次,字节码调度程序只是一个简单地从内存中直接读取,转而间接调度分支程序的过程。因此,执行字节码指令要比访问语法树节点快得多。第三,由于不再需要语法树,解释器无需继续在语法树节点间传送执行状态。

解释器使用字节码之后能够直接从字节码解释的所有的优化中获益匪浅,这也意味着SquirrelFish的速度还会继续得到提升。

在解析器使用字节码之后,我们目前实现的编译时优化有:
  • 常量折叠(constant folding)
  • 更强的拷贝传播
  • 类型推断——包括精确和推测两种方式
  • 基于表达式上下文的特化——尤其是void和boolean上下文
  • 窥孔优化(peephole optimization)
  • 逃逸分析 (escape analysis)

SquirrelFish团队特别对那些在同一领域工作的人们表示了感谢,正是他们的研究成果激发了SquirrelFish的开发灵感。

SquirrelFish的设计很大程度上来自于高效虚拟机领域的一些最新研究成果,其中包括M. Anton Ertl教授、David Gregg教授等人以及Lua编程语言的开发者们的研究。

以上转自InfoQ的《WebKit小组宣布开发基于字节码的JavaScript解释器——SquirrelFish》

2、SquirrelFish的核心WebKit

WebKit,Safari和Safari Mobile的核心引擎,尚未发布的Android也采用WebKit框架。开发者宣布WebKit的核心JavaScript 引擎将有一个新的解释器,代号为SquirrelFish,速度将比前一个版本的解释器有大幅度的提升。

WebKit团队希望推进Safari在JavaScirpt解析器上的呈现能力。通过简化语法,使用更多字节码避免重复使用相同代码。

SquirrelFish是基于寄存器、直接线程的高级字节码引擎,目前的开发才刚刚起步。开发者称已计划好的6个最优化方案将能使速度再次飞跃。

它将通过延时从语法树生成字节码,使用简单的一次编译实现复制生成(copy propagation)。在 SunSpider JavaScript性能测试中,可以看到性能上的大幅提升:

浏览器

由上图可知,SquirrelFish的速度要大幅领先WebKit先前的解释器。实际数据显示,在SunSpider JavaScript性能测试中,SquirrelFish的速度是WebKit先前的解释器的1.6倍。

以上转自《Safari将开发新的解释器SquirrelFish》

3、与Tamarin的性能比较

由上图可以看出  SquirrelFish的速度明显大于Tamarin系列。

具体性能如下表:

.g {text-indent:3px;padding-right:3px;overflow:hidden;white-space:nowrap;letter-spacing:0;word-spacing:0;background-color:#FFFFFF; z-index:1;border-top:0px none;border-left:0px none;border-bottom:1px solid #CCC;border-right:1px solid #CCC;} .dn {display:none} .chip {background-image:url('http://www.google.com/images/spreadsheets/chip.gif'); background-repeat:no-repeat; background-position:top right;} .s4 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:400;font-style:normal;color:#000000;text-decoration:none;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-right:1px solid #CCC;border-bottom:1px solid #CCC;} .s0 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:400;font-style:normal;color:#000000;text-decoration:none;text-align:left;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-top:1px solid #CCC;border-right:1px solid #CCC;border-bottom:1px solid #CCC;border-left:1px solid #CCC;} .s7 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:400;font-style:normal;color:#000000;text-decoration:none;text-align:right;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-right:1px solid #CCC;border-bottom:1px solid #CCC;} .s1 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:400;font-style:normal;color:#000000;text-decoration:none;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-top:1px solid #CCC;border-right:1px solid #CCC;border-bottom:1px solid #CCC;} .s9 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:400;font-style:normal;color:#000000;text-decoration:none;text-align:left;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-right:1px solid #CCC;border-bottom:1px solid #CCC;} .s3 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:400;font-style:normal;color:#000000;text-decoration:none;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-right:1px solid #CCC;border-bottom:1px solid #CCC;border-left:1px solid #CCC;} .s5 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:400;font-style:normal;color:#000000;text-decoration:none;text-align:left;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-right:1px solid #CCC;border-bottom:1px solid #CCC;border-left:1px solid #CCC;} .s8 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:400;font-style:normal;color:#000000;text-decoration:none;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-right:1px solid #CCC;border-bottom:1px solid #CCC;} .s2 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:400;font-style:normal;color:#000000;text-decoration:none;text-align:left;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-top:1px solid #CCC;border-right:1px solid #CCC;border-bottom:1px solid #CCC;} .s6 {background-color:white;font-family:verdana;font-size:100.0%;font-weight:700;font-style:normal;color:#000000;text-decoration:none;vertical-align:bottom;white-space:nowrap;overflow:hidden;text-indent:3px;padding-left:0px;border-right:1px solid #CCC;border-bottom:1px solid #CCC;}            

.

Test   squirrelfish

tamarin-tracing

untyped

tamarin-tracing

typed

.

         

.

sunspider/access-binary-trees.as   33 98 99

.

sunspider/access-fannkuch.as   108 164 119

.

sunspider/access-nbody.as   126 186 182

.

sunspider/access-nsieve.as   30 71 57

.

sunspider/bitops-3bit-bits-in-byte.as   35 16 15

.

sunspider/bitops-bits-in-byte.as   35 47 23

.

sunspider/bitops-bitwise-and.as   59 231 39

.

sunspider/bitops-nsieve-bits.as   70 61 46

.

sunspider/controlflow-recursive.as   20 34 38

.

sunspider/crypto-aes.as   52 193 179

.

sunspider/crypto-md5.as   38 175 190

.

sunspider/crypto-sha1.as   40 46 40

.

sunspider/math-cordic.as   67 60 47

.

sunspider/math-partial-sums.as   104 227 96

.

sunspider/math-spectral-norm.as   37 38 34

.

sunspider/s3d-cube.as   84 179 145

.

sunspider/s3d-morph.as   93 89 78

.

sunspider/s3d-raytrace.as   97 255 138            

.

sunspider/string-fasta.as   87 183 178

.

sunspider/string-validate-input.as   80 4209 4185

.

Aggregate (without string-validate-input)   1215 2353 1743

.

         

.

         

.

Test   squirrelfish tamarin untyped tamarin typed

.

         

.

sunspider/access-binary-trees.as   37 80 83

.

sunspider/access-fannkuch.as   109 139 73

.

sunspider/access-nbody.as   125 202 185

.

sunspider/access-nsieve.as   31 76 43

.

sunspider/bitops-3bit-bits-in-byte.as   26 26 14

.

sunspider/bitops-bits-in-byte.as   37 41 6

.

sunspider/bitops-bitwise-and.as   59 291 21

.

sunspider/bitops-nsieve-bits.as   69 78 45

.

sunspider/controlflow-recursive.as   20 60 65

.

sunspider/crypto-aes.as   50 96 73

.

sunspider/crypto-md5.as   38 56 67

.

sunspider/crypto-sha1.as   40 55 53

.

sunspider/math-cordic.as   66 124 84            

.

sunspider/math-partial-sums.as   105 289 91

.

sunspider/math-spectral-norm.as   37 110 45

.

sunspider/s3d-cube.as   87 134 49

.

sunspider/s3d-morph.as   97 84 55

.

sunspider/s3d-raytrace.as   99 163 94

.

sunspider/string-fasta.as   89 152 129

.

sunspider/string-validate-input.as   82 140 128

.

Aggregate   1303 2396 1403

上表详细列出了不同项目运行不同测试用例的耗时比较,可以明显看出他们之间的差距来。

4、项目网址: http://webkit.org/blog/189/announcing-squirrelfish/