Cedric
--
Cedric Pinson
Provide OpenGL, WebGL and OpenSceneGraph services
+33 659 598 614 - cedric...@plopbyte.com
http://plopbyte.com - http://osgjs.org - http://showwebgl.com
In Chrome, yes, calling typed arrays' set() method with a JavaScript
array as argument is slow. Some recent work has been done -- see
http://crbug.com/84007 -- and some more is ongoing, but I am not sure
how much faster it can be made.
Element-by-element accesses have been highly optimized in V8 and more
optimizations continue there.
-Ken
In both cases an element-by-element copy of the JavaScript array needs
to be made. When doing this copy in JavaScript, the V8 engine gets to
optimize the fetch of each JS array element and the store into the
typed array. When calling the set() method, each JS array element is
fetched using V8's C++ API -- see
http://trac.webkit.org/browser/trunk/Source/WebCore/bindings/v8/custom/V8ArrayBufferViewCustom.h
-- which is currently slow.
> Also, I'm sure there should be more room for performance improvements
> in the use of the set method in Chrome: FF5 is showing 55000 ops/sec
> while Ch14 is showing 1100 (see comparison table below in
> http://jsperf.com/typedarraysetvscreate/2 ).
It is almost certain that this could be optimized further and I've
asked the V8 team about this possibility. Add yourself to the CC: list
of http://crbug.com/84007 if you want to track the progress.
-Ken
https://developer.mozilla.org/en/javascript_typed_arrays
Any positive feedback? If so, I would be willing to create a test for
it as well.
1 var int16View = new Int16Array(buffer);
2
3 for (var i=0; i<int16View.length; i++) {
4 console.log("Entry " + i + ": " + int16View[i]);
5 }
Here we create a 16-bit integer view that shares the same buffer as
the existing 32-bit view and we output all the values in the buffer as
16-bit integers. Now we get the output 0, 0, 2, 0, 4, 0, 6, 0.
You can go a step farther, though. Consider this:
1 int16View[0] = 32;
2 console.log("Entry 0 in the 32-bit array is now " + int32View[0]);
--
Bringing game to younix
Bust0ut Entertainment ---
PureBreedDefense.com --> TheLinuxGame.com --> PBDefence.com
"Finding the exit without looking"