I'm writing some charting animation code where the values for each series
(shape in the chart) are specified as an array of numbers.
When series data changes, say from start -> end, I compute the delta
something like so:
var start = [1, 2, 3, 4, 5];
var end = [3, 2, 1, 4, 4];
var deltas = [2, 0, -2, 0, -1];
To animate, I tween a deltaPercent between 0 and 1 and use
requestAnimationFrame to compute the current series values like so:
var deltaPercent = 0.5;
var current = start.slice();
var i, length = current.length;
for (i=0; i<length; i++) {
current[i]+= deltas[i] * deltaPercent;
}
This is nice and simple, but things get a little more interesting when the
requirement that some series values can be missing/unspecified is
introduced to the mix.
For the purposes of deltas, I can treat undefined to be like 0 when the
opposite value at start/end is not undefined, to get something like this:
var start = [1, undefined, 3, undefined, 5];
var end = [3, 2, 1, undefined, undefined];
var cleanStart = [1, 0, 3, undefined, 5];
var cleanEnd = [3, 2, 1, undefined, 0];
var deltas = [2, 2, -2, 0, -5];
Then my animation code becomes something like this:
var deltaPercent = 0.5;
var current = cleanStart.slice();
var i, length = current.length;
for (i=0; i<length; i++) {
if (deltas[i] !== 0) {
current[i]+= deltas[i] * deltaPercent;
}
}
My concern is how I can optimize this logic, since my application can have
many series with many values (ex: > 50 arrays with length > 100) and needs
to run this code at 60 frames per second to achieve a smooth animation
effect.
Having read some posts about v8 performance tips
(http://www.html5rocks.com/en/tutorials/speed/v8/) I understand that arrays
have a hidden class & type.
My understanding of how v8 optimization works is that the presence of
undefined in my arrays will cause v8 to no longer optimize for a
number-only array.
Anyone have any thoughts / suggestions for how to improve performance for
this scenario?
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.