[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] typed array convenience



Being able to do typed array memcpys without allocating new typed array views would be very much preferred by Emscripten applications. A lot of Emscripten-generated garbage comes from this origin, and the impact of this to Firefox is being discussed at https://bugzilla.mozilla.org/show_bug.cgi?id=936168

In Emscripten specifically to implement memcpy, we have observed typed array .set() to be slower than manually looping over bytes for small copies, so in Emscripten, short <4K element memcpys do a for loop over the data, and only larger ones do a typed array .set() call. I suspect Florian's example of very small ~1K range of copying won't get any faster if there are JS function calls involved.

2014-10-28 16:56 GMT+02:00 Jussi Kalliokoski <jussi.kalliokoski@gmail.com>:
On Tue, Oct 28, 2014 at 4:19 PM, Florian Bösch <pyalot@gmail.com> wrote:


On Tue, Oct 28, 2014 at 2:42 PM, Jussi Kalliokoski <jussi.kalliokoski@gmail.com> wrote:
On Tue, Oct 28, 2014 at 3:15 PM, Mark Callow <khronos@callow.im> wrote:

On Oct 28, 2014, at 8:04 PM, Florian Bösch <pyalot@gmail.com> wrote:

I propose an addition to the typed array specification that introduces these methods like
  • argcpy(uint dstOffset, arguments...)
  • arrcpy(uint dstOffset, Array|TypedArrayView someArray)
dst.set(someArray, dstOffset);

dst.set(0, 1, 2, 3, 4) --> invalid argument errort, not a substitute for argcpy suggestion.

Didn't try to be. :)
 
dst.set([1,2,3,4], dstOffset) is substantially slower than one at a time assignment (it's the second slowest method in fact). Updated jsperf http://jsperf.com/typed-array-fast-filling, attached screenshot http://codeflow.org/pictures/typed-array-test.png, blue on the bottom is array.set.

That can only be improved by improving the implementations, adding a new method that does the exact same thing (except that the arguments are reversed) won't help. I doubt the arguments-based one would be any better, since I'm quite skeptic that arguments objects have better performance characteristics (in terms of memory, GC or allocation time) than arrays.
 
 
  • memcpy(uint dstByteOffset, TypedArray[View] origin, uint srcByteOffset, uint srcByteCount)
dst.set(src.subarray(srcOffset, srcOffset + srcByteCount), dstOffset);

You do not want to allocate an object a million times if you can avoid it in an on-line preprocessing step to copy memory from one array to another. Likewise, you do not want to allocate a GCed object oftentime at runtime for fairly obvious reasons.

Obviously. Maybe we could introduce optional arguments for srcOffset and srcEnd to set(). Or add a new method to avoid overloading costs.

- Jussi