简体   繁体   English

为什么asm.js项目在Chrome和FireFox中的运行速度更快?

[英]Why is asm.js project running faster in Chrome then FireFox?

I have ported a game engine project for my university course from C/C++ to JavaScript using emscripten. 我已经使用emscripten将我的大学课程的游戏引擎项目从C / C ++移植到JavaScript。 The asm.js optimization flag is set and I have been measuring the performance. asm.js优化标志已设置,我一直在测量性能。 But what is puzzling is that the performance in Firefox is bad. 但令人费解的是,Firefox中的性能很糟糕。 While the project runs very well in Chrome and Opera. 虽然该项目在Chrome和Opera中运行良好。 This doesn't make sense to me given that FireFox is the browser utilizing asm.js optimization. 鉴于FireFox是使用asm.js优化的浏览器,这对我来说没有意义。

This project is a downhill slalom racing game using SDL and WebGL. 这个项目是一个使用SDL和WebGL的下坡障碍赛车游戏。 Running in Firefox on my laptop the profiler shows that the demo is completely bound by the CPU, the bottleneck appearing around _SDL_LockSurface() and _TTF_RenderText_Solid(). 在我的笔记本电脑上运行Firefox,分析器显示该演示完全受CPU限制,瓶颈出现在_SDL_LockSurface()和_TTF_RenderText_Solid()周围。 These are used to render the dynamic text among other things. 这些用于渲染动态文本等。

And yet in Chrome the CPU is idle most of the time on the same system. 然而在Chrome中,CPU在同一系统上大部分时间处于空闲状态。 And performance is similar in Opera. Opera的性能也很相似。 Does this mean the asm.js optimization is not working? 这是否意味着asm.js优化不起作用? Firefox reports the asm.js code has compiled successfully. Firefox报告asm.js代码已成功编译。 So why is this optimization backfiring and resulting in execution that is at best half the frame rate? 那么为什么这种优化会得到回火并导致执行最多只有帧速率的一半? I've tested with FF version 28, also the current nightly build. 我已经测试了FF版本28,也是当前的夜间版本。 The demo can be found here, http://www.susurrus.mars-station.com/page7.php?lang=en 该演示可在此处找到, http://www.susurrus.mars-station.com/page7.php?lang = en

I was thinking about this question for a long time and I might have an answer for you. 我很长一段时间都在考虑这个问题,我可能会给你一个答案。 Simply, get rid of canvas.getContext('2d') . 简单地说,摆脱canvas.getContext('2d') I guess asm.js is not your problem at all. 我想asm.js根本不是你的问题。

As @BorisZbarsky said, these are graphic calls that has nothing to do with asm.js. 正如@BorisZbarsky所说,这些是与asm.js无关的图形调用。 You answered that these run without difficulty. 你回答说这些运行毫无困难。 I tested it on my own and a lot of things that can follow after getContext as 2D is heavy graphic operation, that you really can't do at realtime fps. 我自己测试了它,并且在getContext之后可以使用很多东西,因为2D是重图形操作,你真的不能在实时fps上做。

Simple example there: http://jsfiddle.net/windkiller/8r3gP/ It is very simple animation, but it eats 60% of my cpu. 那里有一个简单的例子: http//jsfiddle.net/windkiller/8r3gP/这是非常简单的动画,但它占我的CPU的60%。

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

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