简体   繁体   English

为什么drawImage在Safari中的执行速度比Chrome或Firefox快得多?

[英]Why does drawImage perform so much faster in Safari than Chrome or Firefox?

I made a little HTML canvas visualizer for fun, and I have noticed that it runs horribly in Chrome, pretty bad in Firefox, but absolutely amazingly in Safari, including iPhone and iPad! 我做了一个小小的HTML canvas可视化工具,很有趣,并且我注意到它在Chrome中运行非常糟糕,在Firefox中非常糟糕,但是在Safari(包括iPhone和iPad)中绝对令人惊讶!

Can anyone explain why? 谁能解释为什么?

I think the code should be fairly straightforward, but basically I'm drawing points for mouse (or touch) location(s), then copying the canvas to a temporary canvas using drawImage. 我认为代码应该相当简单,但是基本上我是在为鼠标(或触摸)位置绘制点,然后使用drawImage将画布复制到临时画布。 From there I clear the display canvas, then copy the temp canvas back (4 times), but applying a few things like rotation, offset, transparency and scale (and playing around with some different globalCompositeOperations), all using drawImage. 从那里我清除了显示画布,然后将临时画布复制回了4次,但是应用了诸如drawing,旋转,偏移,透明度和缩放(以及使用一些不同的globalCompositeOperations)之类的一些东西。 So in total, drawImage is called 5 times in each loop. 因此,总共,在每个循环中drawImage被调用5次。

You can view the demo here: http://lakenen.com/vis.html 您可以在此处查看演示: http : //lakenen.com/vis.html

Any insight would be greatly appreciated! 任何见解将不胜感激!

PS. PS。 try this on an iPad if you can; 如果可以,请在iPad上尝试; it's pretty neat with multi-touch :) 多点触控非常简洁:)

Since the performance profiler is pretty much identical in Safari and Chrome you should be able to determine this yourself. 由于性能分析器在Safari和Chrome中几乎相同,因此您应该可以自行确定。 Your demo runs fine on both Safari and Chrome on my machine. 您的演示可以在我的机器上的Safari和Chrome上正常运行。

Anyway, I can't tell you why drawImage performs worse on Chrome than Safari, only that it does when an image fails to load and is then drawn. 无论如何,我无法告诉您为什么drawImage在Chrome上比Safari表现更差,仅当图像无法加载然后被绘制时才如此 Otherwise Chrome seems faster on Windows. 否则,Chrome在Windows上似乎更快。

Here's a simple jsperf I made a while ago. 这是我前一段时间做的一个简单的jsperf。 It seems to show chrome 19 running twice as fast as safari on my windows 7 machine. 看来Chrome 19在我的Windows 7机器上的运行速度是野生动物园的两倍。

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

相关问题 为什么打电话比申请快得多? - Why is call so much faster than apply? 为什么Chrome,Firefox和IE上的文本看起来比Safari模糊? - Why does text on Chrome, Firefox, and IE look fuzzier than Safari? 为什么parseInt()比Firefox中的* 1慢得多? - Why is parseInt() so much slower than *1 in Firefox? 为什么检查void 0比检查undefined快得多? - Why is checking void 0 so much faster than checking undefined? 为什么异步代码比同步代码快得多? - Why is async code considered so much faster than synchronous? 为什么使用 JavaScript 对 32 位数字进行排序比对 33 位数字进行排序快得多? - Why does sorting 32-bit numbers using JavaScript so much faster than sorting 33-bit numbers? Javascript:为什么这个基准测试显示array.shift()在读取数组中的值时比array [i]快得多? - Javascript: Why does this benchmark show array.shift() to be so much faster than array[i] at reading off values from an array? 大型子串在Firefox中比Chrome快9000倍:为什么? - Large substrings ~9000x faster in Firefox than Chrome: why? 为什么 Firefox 运行此代码的速度比 Chrome 快 10 倍 - why Firefox runs this code 10x faster than Chrome 在Firefox上运行HTML5 Canvas的速度比在Chrome上更快! 为什么? - HTML5 Canvas faster on Firefox than on Chrome! Why?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM