Interesting indeed. I use Typed Arrays (and fixed them for v0.7.x) quite extensively in node-webgl and node-webcl and indeed I was quite puzzled by that implementation. I encountered the same performance issues you mentioned. In my modules I used fast buffers to avoid penalty of copying that I wrap within ArrayBuffers. I have tested the DataViews albeit not extensively, as you can see in node's test-typed-arrays.js.
I'm going to look at your implementation and see if I have better performance. @Tim: I have ported your node knockout wavefront demo as example in node-webgl. It runs way faster than in the browser ;-) On Wednesday, April 11, 2012 10:01:50 AM UTC-7, Stéphan Kochen wrote: > > I noticed that TypedArrays use `calloc`, when not backed by a Buffer, > which seemed like something that'd be slow. I sat down and wrote a quick JS > implementation, that relies only on Buffer and a slightly modified > `SlowBuffer.makeFastBuffer`. It's a stand-alone package at: > https://github.com/stephank/node-arrays > > It requires Node 0.7.7, which includes Buffer alignment fixes. It passes > the WebGL conformance tests. I made a quick benchmark to compare > performance with the native implementation currently in Node. On the two > Macs I have access to, I get about the same numbers: > > $ node test/benchmark.js > Small ArrayBuffer: 0.00149 ms (native) vs. 0.000603 ms (pure-js), ×0.40 > Large ArrayBuffer: 0.007311 ms (native) vs. 0.008317 ms (pure-js), > ×1.14 > Small Int8Array: 0.001472 ms (native) vs. 0.00066 ms (pure-js), ×0.45 > Large Int8Array: 0.007359 ms (native) vs. 0.008385 ms (pure-js), ×1.14 > > For small allocations, there's a clear win from Buffer's pooling. There's > a slight loss for allocations exceeding the pool size, but then again, I've > not yet profiled the code. > > If anyone feels the need to try this on a real world project, there's a > node branch at: > https://github.com/stephank/node/tree/js-arrays > > Note that there are slight differences in behavior for stuff that falls > outside the spec; see: > https://github.com/stephank/node/commit/3c13517a > > -- > Stéphan Kochen > > >
