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

[Public WebGL] Typed Array setter for partial arrays (and typed array performance)



Hi,

Because I keep needing to do it, I have become irritated by the lack of a function in the typed array specification do copy the partial contents of a JS source array, something like:

     void set(type[] array, optional unsigned long offset, unsigned long srcOffset, unsigned long count)

The obvious answer is a wrapper but I suspected that a loop of, e.g, i16array[i] = src[i] in JS would be slower than something internal to the typed array implementation. I wrote a short test for this. The result on FF4 is as I expected:

Int16Array.set(2000 byte array) x 100 times took 1ms (400000000 bytes/second).

Int16Array[j] = data[j] 2000 x 100 times took 4ms (100000000 bytes/second).

Int16Array.set(200000 byte array) x 1 times took 1ms (400000000 bytes/second).

Int16Array[j] = data[j] 200000 x 1 times took 4ms (100000000 bytes/second).

To ensure the result is not influenced by smart optimizers the test is repeated with a longer array and a single iteration. The bytes copied is the same in each case.

The "wrapper" runs at one quarter the speed of a native implementation so I think the above described set function is a badly needed addition to typed arrays.

If the source is a typed array, one can always create another view or subarray so it is not so important to add a new function for this case, though there is the issue of the garbage that must then be collected.

When I ran the same test on Chromium 12.0.717.0 (79525) I got a very surprising result:

Int16Array.set(2000 byte array) x 100 times took 49ms (8163265.306122449 bytes/second).

Int16Array[j] = data[j] 2000 x 100 times took 6ms (66666666.666666664 bytes/second).

Int16Array.set(200000 byte array) x 1 times took 38ms (10526315.789473685 bytes/second).

Int16Array[j] = data[j] 200000 x 1 times took 24ms (16666666.666666666 bytes/second).

It is surprising for 3 reasons:
The test is attached.

Regards

-Mark




Title: Test performance of array to ArrayBuffer copy
begin:vcard
fn:Mark Callow
n:Callow;Mark
org:HI Corporation;Graphics Lab, Research & Development
adr:Higashiyama 1-4-4, Meguro-ku;;Meguro Higashiyama Bldg 5F;Tokyo;;153-0043;Japan
email;internet:callow_mark@hicorp.co.jp
title:Chief Architect
tel;work:+81 3 3710 9367 x228
tel;fax:+81 3 5773 8660
x-mozilla-html:TRUE
url:http://www.hicorp.co.jp,  http://www.mascotcapsule.com
version:2.1
end:vcard