简体   繁体   English

jsflot,html5 canvas和setInterval的性能

[英]performance with jsflot, html5 canvas and setInterval

I am developing a webpage which has 9 jQuery Flot graphs which are updated with 我正在开发一个网页,其中包含9个更新的jQuery Flot图

setInterval(function(){
    updateGraph1to8(data1);
}, 10);

setInterval(function(){
    updateGraph9(data2);
}, 10);

and three HTML5 canvas which instead is updated on an event. 和三个HTML5画布,而不是在事件上更新。 Two of them are based on data1 so they are drawn inside the event function that supply data1 like: 其中两个基于data1因此它们被绘制在提供data1的事件函数中,如:

onData1available(){
    //do math and stuff
    updateCanvas1();
    updateCanvas2();
}

while the remaining is based on data2 and is drawn in the same way. 其余的基于data2并以相同的方式绘制。

JS Flot graphs are drawn constantly as soon as the document is ready, they have no lag at all. 文档准备就绪后,JS Flot图表会不断绘制,它们完全没有滞后。 By the time I activate the canvas (the drawing is activated when a button is pressed), I notice a clear lag in the Flot graphs but none in the canvas. 当我激活画布时(按下按钮时图形被激活),我注意到Flot图形中的明显滞后但画布中没有。 I tried to move the Flot graphs drawing in the event function but everything was lagging as hell. 我试图在事件功能中移动Flot图形,但一切都落后了。 Then I tried to bring the canvases in a timer but it didn't really change anything. 然后我试着将画布带到计时器中,但它并没有真正改变任何东西。 My questions are: 我的问题是:

  1. Am I really reaching a performance bottleneck? 我真的遇到了性能瓶颈吗? (to me it's impossible) (对我来说这是不可能的)
  2. What should be the best implementation to follow? 应该遵循什么样的最佳实施?
  3. How do I enhance my code in order to avoid lag? 如何增强代码以避免滞后?
  4. I thought asynchronous coding was a good way to avoid this thing, then why the timers aren't doing their job? 我认为异步编码是一种避免这种情况的好方法,那么为什么计时器不能正常工作呢? Is it because they are all scheduled at 10ms? 是因为他们都安排在10ms? Is a sequential delay improving the situation? 顺序延迟改善了这种情况吗?

SOLUTION: 解:

http://jsfiddle.net/wMkJg/ http://jsfiddle.net/wMkJg/

SOLUTION: 解:

Solved using window.requestAnimationFrame trick 使用window.requestAnimationFrame技巧解决了问题

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

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