Topic: JS animation performance: reflow/redraw cost, CPU use? (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: schillmania.com |
posted 11-01-2008 19:56
OK, this is a rather open-ended JS performance question, but one I imagine many people have wondered about. I've been considering redoing a "snow" script which I wrote many years ago, my main gripe with it (and others) is the CPU use; perhaps it's simply expensive to redraw many elements, but the performance numbers seem to vary widely between browsers. |
Nervous Wreck (II) Inmate From: Germany |
posted 11-02-2008 00:50
I don't know whether this will increase speed a lot... But the bottleneck seems to lie in this.move. Here are 4 (random?) ideas, which just happen to pop into my head. code: this.o.style.left = ... -> this.S.left = ...
code: for (var i=this.flakes.length-1; i>0; i--) { if (this.flakes[i].active == 1) { this.flakes[i].animate(); active++; } else if (this.flakes[i].active == 0) { used++; } else { waiting++; } } -> for (var f, i=0; f = this.flakes[i++];) { if (f.active == 1) { f.animate(); active++; } else if (f.active == 0) { used++; } else { waiting++; } }
code: setInterval("snowStorm.snow()",75) -> setInterval(snowStorm.snow,75)
|
Paranoid (IV) Inmate From: Norway |
posted 11-02-2008 16:43
In my experience JavaScript is rarely, if ever, the bottleneck when doing animations. code: Number of elements processed @ 25 fps: +---------+---------+-------+-------+ | JS only | bg only | GIF | PNG32 | +-----------------+---------+---------+-------+-------+ | Op 9.62 10467 | 80,225 | 1,470 | 700 | 755 | +-----------------+---------+---------+-------+-------+ | Fx 3.1b1 | 42,000 | 715 | 470 | 420 | +-----------------+---------+---------+-------+-------+ | Sf 4dp2 528.1.1 | 53,250 | 1,425 | 900 | 860 | +-----------------+---------+---------+-------+-------+ | IE 8b2 | 28,250 | 370 | 230 | 230 | +-----------------+---------+---------+-------+-------+ | IE 8b2* | 28,200 | 945 | 375 | 360 | +-----------------+---------+---------+-------+-------+ | Cr 0.3.154.9 | 66,750 | 2,350 | 2,030 | 1,940 | +-----------------+---------+---------+-------+-------+ * in Compatibility mode For the JS only runs, the elements were not appended to the DOM. This very test only served to show how JS alone doesn't cost much. |
Paranoid (IV) Inmate From: Norway |
posted 11-03-2008 12:02
Note:
|
Paranoid (IV) Inmate From: Norway |
posted 11-03-2008 19:41
code: Number of elements processed @ 25 fps: +---------+---------+-------+-------+-------+ | JS only | bg only | GIF | PNG32 | text | +-----------------+---------+---------+-------+-------+-------+ | Op 9.62 10467 | 80,225 | 1,470 | 700 | 755 | 975 | +-----------------+---------+---------+-------+-------+-------+ | Fx 3.1b1 | 42,000 | 715 | 470 | 420 | 360 | +-----------------+---------+---------+-------+-------+-------+ | Fx 3.1b1 jit | 40,575 | 725 | 475 | 410 | 385 | +-----------------+---------+---------+-------+-------+-------+ | Sf 4dp2 528.1.1 | 53,250 | 1,425 | 900 | 860 | 965 | +-----------------+---------+---------+-------+-------+-------+ | IE 8b2 | 28,250 | 370 | 230 | 230 | 225 | +-----------------+---------+---------+-------+-------+-------+ | IE 8b2* | 28,200 | 945 | 375 | 360 | 525 | +-----------------+---------+---------+-------+-------+-------+ | Cr 0.3.154.9 | 66,750 | 2,350 | 2,030 | 1,940 | 1,250 | +-----------------+---------+---------+-------+-------+-------+ |
Paranoid (IV) Inmate From: schillmania.com |
posted 11-03-2008 19:55
P01: Fancy stats! Thanks for digging in, I'll take some time later to check this out. I'm interested in general animation performance in particular, of course, though the snow script is a decent real-world example which could be optimized further. |
Paranoid (IV) Inmate From: Umeå, Sweden |
posted 11-03-2008 23:28
I blogged a bit about timers a while back. http://web-graphics.com/2007/03/06/timer-resolutions-and-browsers/ |
Paranoid (IV) Inmate From: schillmania.com |
posted 11-07-2008 23:56
John Resig has also written about JS timers (how they work), and performance. The latter has some interesting graphs showing timing data between browsers. It looks like Safari nails timings quite wonderfully. These tests are nearly a year old, so things may be fairly different in nightly builds of Opera, Firefox etc. |
Paranoid (IV) Inmate From: Norway |
posted 11-10-2008 17:57
Robert Kieffer has announced JSLitmus a tool to allow to quickly and easily write performance tests. It comes with a set of tests incrementing a variable in various scopes and shows, if need be, that local variables are much faster than global variables. But what surprises me is the cost of closures in Fx 3.0.3. |
Bipolar (III) Inmate From: |
posted 05-31-2011 11:10
Edit TP: spam removed
|