简体   繁体   English

编译为JS的Dart代码似乎比Dart快(在Dartium中)

[英]Dart code compiled to JS seems to be faster than Dart (in Dartium)

Impressed by the performance of Dart I put together a quite simple web-app to render the Mandelbrot set in Dart (using HTML5 canvas). Dart的性能给我留下了深刻印象,我将一个非常简单的Web应用程序组合在一起,以渲染Dart中的Mandelbrot(使用HTML5画布)。 This is by all means not meant as a realistic performance test. 这绝不是一个真实的性能测试。 The page renders the Mandelbrot set in a 800x600 canvas with a max-depth of 10.000. 该页面将Mandelbrot设置为800x600画布,最大深度为10.000。 The app can be seen here: http://goo.gl/DLuQp 该应用程序可以在这里看到: http//goo.gl/DLuQp

What puzzles me: running in Dartium the image renders in about 8.5 seconds (which is impressive). 令我困惑的是:在Dartium中运行时,图像渲染时间约为8.5秒(令人印象深刻)。 The same page in Firefox takes >15 seconds. Firefox中的同一页面需要> 15秒。 No surprise there. 这并不奇怪。

But running the same page in Chrome (version 27.0.1453.93), which does not run Dart but the JS version as well completes in 6.7 seconds, faster than Dart? 但是在Chrome(版本27.0.1453.93)中运行相同的页面,它不运行Dart但JS版本也在6.7秒内完成,比Dart快?

Why is that so? 为什么会这样?

UPDATE: I added a "Run" button to re-render the canvas (to verify warm-up behaviour). 更新:我添加了一个“运行”按钮来重新渲染画布(以验证预热行为)。 Also I added a JS-only version (same code of course) to check JS in Dartium. 另外我添加了一个只有JS的版本(当然是相同的代码)来检查Dartium中的JS。 In short: the figures and my question remains as is. 简而言之:数字和我的问题仍然存在。 Warm-up seems to have no effect. 热身似乎没有效果。 The JS-version is faster in Dartium than the Dart-version. 在Dartium中,JS版本比Dart版本更快。

UPDATE after closed question: Just for the record: in this specific case moving the code into parallel workers/isolates not only resulted in a significant performance boost, also Dart now clearly leaves the JS-version behind in the dust by factor 10. 关闭问题后更新:仅供记录:在这个特定情况下,将代码移动到并行工作者/隔离器不仅导致显着的性能提升,Dart现在明显地将JS版本置于尘埃落后的因素10。

There could be several reasons. 可能有几个原因。 Out of the top of my head: 脱离我的头脑:

  • Dart VM misses out on some optimizations. Dart VM错过了一些优化。 V8 is much older than the Dart-VM and some optimizations just didn't make it into Dart yet. V8比Dart-VM要老得多,而且一些优化还没有进入Dart。
  • You are not running a warmup run. 你没有运行热身运行。 The Dart-VM currently does not do OSR (on-stack replacement). Dart-VM目前不执行OSR(堆栈替换)。 When a function is invoked it will finish in the same "mode" in which it was started. 调用函数时,它将以启动它的相同“模式”结束。 That is, if an important function is started in non-optimized mode, but contains a loop that is really important (and runs for a long time) then the Dart VM will not replace it with the optimized version. 也就是说,如果一个重要的函数在非优化模式下启动,但包含一个非常重要的循环(并且运行很长时间),那么Dart VM将不会用优化版本替换它。 An easy workaround is to execute the function (possibly with a smaller value) first so that the function gets optimized. 一个简单的解决方法是首先执行函数(可能具有较小的值),以便优化函数。 Eventually OSR will make it into the Dart VM. 最终OSR将进入Dart VM。
  • Make sure you don't run in checked mode. 确保您没有在检查模式下运行。 The Dart-VM can be much faster in unchecked mode. 在未选中模式下,Dart-VM可以更快。

It's a known issue with the canvas bindings and APIs. 这是canvas绑定和API的已知问题。 See http://dartbug.com/10344 http://dartbug.com/10344

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM