JRuby 新 JRuby: 超快 JIT w/ Graal & Truffle

ksec · 2014年01月10日 · 最后由 ksec 回复于 2015年10月28日 · 10224 次阅读

From Charles Nutter in Twitter https://twitter.com/headius

Truffle allows you to just generate the AST interpreter for your language, and it turns that into an optimizing JIT

Graal = New JVM

很 Raw, Project 還是試驗性的。

Benchmarks https://gist.github.com/headius/8328831

# interpreted AST

system ~/projects/jruby $ jruby.bash -X-C mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
4.862
4.822
4.822
4.846
5.057
5.018
4.827
4.864
4.876
4.858
4.863
4.83
4.81
4.832
4.873
4.883
4.888
4.871
4.85
4.831

# interpreted IR

system ~/projects/jruby $ jruby.bash -X-CIR mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
5.199
5.118
5.091
5.115
5.056
5.124
5.041
5.003
5.029
5.013
4.983
5.011
5.013
5.025
5.07
5.022
4.995
5.031
5.012
4.992

# Compiled AST, no invokedynamic

system ~/projects/jruby $ jruby.bash -Xcompile.invokedynamic=false mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
0.732
0.745
0.715
0.73
0.72
0.726
0.739
0.746
0.792
0.817
0.82
0.823
0.814
0.78
0.723
0.727
0.745
0.723
0.746
0.724

# Compiled AST, with invokedynamic

system ~/projects/jruby $ jruby.bash mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
0.597
0.601
0.611
0.602
0.606
0.588
0.605
0.593
0.609
0.6
0.59
0.61
0.614
0.598
0.605
0.591
0.61
0.593
0.596
0.589

# Compiled IR, with invokedynamic

system ~/projects/jruby $ jruby.bash -X+CIR mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
2.171
0.722
0.708
0.697
0.704
0.692
0.706
0.702
0.698
0.694
0.695
0.689
0.704
0.703
0.702
0.698
0.697
0.719
0.708
0.692

# Interpreted IR with unboxing (no boxing guards)

system ~/projects/jruby $ jruby.bash -X-CIR -Xir.unboxing=true mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
2.454
2.459
2.393
2.377
2.39
2.46
2.385
2.373
2.393
2.399
2.449
2.568
2.726
2.395
2.407
2.438
2.384
2.387
2.4
2.479

# Compiled IR, with invokedynamic and unboxing (without boxing guards)

system ~/projects/jruby $ jruby.bash -X+CIR -Xir.unboxing=true mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
0.565
0.312
0.097
0.098
0.104
0.097
0.097
0.106
0.108
0.097
0.114
0.102
0.098
0.095
0.094
0.096
0.096
0.097
0.097
0.095

# Truffle AST interpreter without Graal JIT

system ~/projects/jruby $ jruby.bash -Xtruffle mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
21.662
21.815
22.059
22.247
21.903
22.222
22.228
21.854
21.997
22.368
22.665
22.632
22.125
21.986
21.941
22.508
22.049
22.547
24.453
25.782

# Truffle AST interpreter plus Graal JIT

system ~/projects/jruby $ jruby.bash -Xtruffle mandelbrot.rb 20
warming up
[truffle] optimized Method mandelbrot_foo:(name):1@10e41621 34aa3427 |Nodes 332 |Time 2169(1630+540 )ms |Nodes 717/ 1105 |CodeSize 7696
running mandelbrot(500) for 20 iterations
0.048
0.048
0.048
0.046
0.048
0.047
0.048
0.048
0.047
0.047
0.047
0.048
0.047
0.046
0.053
0.048
0.048
0.048
0.05
0.049

system ~/projects/jruby $ ../rubinius/bin/rbx mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
1.777457
1.813019
1.823906
1.8459219999999998
1.776521
1.798789
1.80667
1.8231220000000001
2.018687
1.982492
1.832832
1.808677
1.810901
1.8509929999999999
1.828273
1.818692
1.8148900000000001
1.786165
1.780102
1.776106

system ~/projects/jruby $ rvm ruby-2.1 do ruby mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
1.864769
1.863214
1.856388
1.854244
1.847911
1.89504
1.898902
1.851657
1.843574
1.866589
1.886925
1.87296
1.846614
1.86955
1.848435
1.921733
1.841216
1.856
1.85546
1.877311

system ~/projects/jruby $ ../topaz/bin/topaz mandelbrot.rb 20
warming up
running mandelbrot(500) for 20 iterations
0.0593700408936
0.0568559169769
0.0556919574738
0.0560510158539
0.0551681518555
0.0552649497986
0.0546820163727
0.0579178333282
0.0544011592865
0.0559079647064
0.0561909675598
0.0547771453857
0.0551559925079
0.0554881095886
0.0549249649048
0.0552458763123
0.0564270019531
0.0546000003815
0.0535879135132
0.0573658943176

一个新的 java 虚拟机?

哎。。 项目只能用 jruby1.6.8 的,好苦逼。。

最后的 topaz 是啥? 就是不知道啥时候能正式上市使用。

#4 楼 @jiayp 已經停止開發了,或者 Topaz 本來就是一個 test project. 其實世界很現實, 沒有小小金錢回報是很難生存。 最近 RailsBricks 是一個例子。 不像 Python, 有很多 Unicorn ( Dropbox ) 甚至 Google 自己有 Engineer 去 Commit Cpython 或者 Pypy。 當然 Ruby 也有, JRuby 有 Red Hat + Oracle, 不過最大問題是 Java / JVM...........

#5 楼 @ksec 只能寄希望与 jruby,就不知道优化的版本啥时候能出来

#6 楼 @jiayp 除了 Enterprise 很難想像 JRuby 會在 Startup 或其他範圍會用, 反而 IBM 有個 Method JIT 的 CRuby Drop in Replacement...........

需要 登录 后方可回复, 如果你还没有账号请 注册新账号