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

Re: [Public WebGL] Matrix objects in JavaScript



On Thu, Mar 21, 2013 at 4:47 PM, Ben Adams <thundercat@illyriad.co.uk> wrote:
>
>> >>> On Thu, Mar 21, 2013 at 2:40 PM, Florian Bösch <pyalot@gmail.com>
>> >>> wrote:
>> >>>>
>> >>>> On Thu, Mar 21, 2013 at 10:16 PM, Rik Cabanier <cabanier@gmail.com>
>> >>>> wrote:
>> >>>>>
>> >>>>> Which one is faster:
>> >>>>>
>> >>>>> element.style.transform =
>> >>>>> window.getComputedStyle(element).transformMatrix.rotateBy(45); // 1
>> >>>>> temporary object. all calculations on c++ side
>> >>>>>
>> >>>>> or
>> >>>>>
>> >>>>> ... make sure some js library is loaded
>> >>>>> element.style.transform = new
>> >>>>>
>> >>>>> MyMatrix(window.getComputedStyle(element).transform).rotateBy(45).getFloatArray();
>> >>>>> // 2 (or 3) temporary objects + 6 or 16 (12 or 32?) temporary floats
>> >>>>> + all
>> >>>>> calculations on js side
>> >>>>
>> >>>>
>> >>>> Neither, this one is faster:
>> >>>>
>> >>>> mat4Rotate(window.getComputedStyle(element).transform, 45,
>> >>>> element.style.transform)
>> >>>>                                                               ^
>> >>>> source
>> >>>> ^a                        ^ target
>> >>>>
>> >>>> We're quite serious when we say temporaries/allocation is a serious
>> >>>> problem, seriously, we're not joking. And lengthy discussions on the
>> >>>> GC
>> >>>> issue have been conducted with only one clear outcome, while things
>> >>>> may get
>> >>>> better, they will not get perfect.
>> >>>
>>
>> There is more work to be done. In Chrome, the typed array
>> implementation is being moved from the browser into the JavaScript
>> engine. This will both speed up typed array allocation, which is
>> currently quite slow in Chrome, as well as track the ECMAScript 6
>> specification, which incorporates typed arrays into the language.
>>
>
> Does this mean you may be able to do something like:
>
>
>     var v1 = new Float32Array([1,2,3,4]);
>     var v2 = new Float32Array([4,3,2,1]);
>
>     v1 *= v2;
>     // v1 == [4.0,6.0,6.0,4.0]
>     v2 += v1;
>     // v1 == [8.0,9.0,8.0,5.0]
>
> Then the if/maybe of SSE/etc interop could, if desired, be handled behind
> the scenes when available. And I'm sure then people could write these high
> performance javascript matrix libraries

I don't know what additional APIs ES6 will end up providing. However,
I think the best direction for SIMD optimization of typed arrays is to
expose the low-level operations. John McCutchan's SIMD API for Dart
looks well designed to me, and I believe it's under discussion for
inclusion in a future version of ECMAScript.
http://highscalability.com/blog/2013/3/20/dart-is-it-the-future-of-the-web.html

-Ken


> Or is that too much hope?
>
> Ben
>
>>
>> -Ken
>>
>

-----------------------------------------------------------
You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl
-----------------------------------------------------------