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

Re: [Public WebGL] typed array convenience

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