开发者

loop is too slow for IE7/8

I have a loop execution 开发者_如何学Cthat needs to run in all browsers.

in chrome/ff etc the execution runs fast and fine. in IE it's slow and end's up dispatching a prompt saying a script is running slow (no good).

Any ideas on how to get around something like this? I mostly just need to get rid of the IE prompt for 7/8

** edit **

Here's code:

if(this.handicap()) {
    while(this.hasGraphChanged()) {
        this.gravity(this.separate());
    }
}

This is a VERY large project, so instead of listing all the code, I'll go for a quick explanation.

this.handicap: returns true if the browser if IE7/8 this.hasChanged: returns true/false depending if there is a change AFTER a draw update this.gravity: processes drawing algorithm based on p1(array)


You can use some asynchronous iteration technique instead of loops. Watch Asynchronous Iteration Patterns by Pedro Teixeira for a nice introduction. It uses Node.js but you can use the same patterns in the browser.


What exactly does the loop do? Is the number of iterations deterministic? If this is something which is causing the browser to hang you may want to consider javascript worker-threads https://developer.mozilla.org/En/Using_web_workers (although I'm not sure which browsers currently support this feature).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜