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

Re: [Public WebGL] Matrix objects in JavaScript



On Fri, Mar 22, 2013 at 2:45 AM, Kenneth Russell <kbr@google.com> wrote:

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

There's a low-level API called the DSP API [1] in the works. The current version aims to solve mostly the problems of audio (it's being developed by the Audio WG [2]), but the plan is that future versions support more features such as 2D convolution etc. . The API can easily take leverage not just SIMD but also parallelizing if necessary.

So far, there's no browser implementation (AFAIK), but there's a JS polyfill [3], a native node implementation [4], and an ex-colleague of mine is prototyping a SpiderMonkey implementation.

Cheers,
Jussi

[1] http://people.opera.com/mage/dspapi/
[2] http://www.w3.org/2011/audio/
[3] http://people.opera.com/mage/dspapi/dspapi.js
[4] https://github.com/jussi-kalliokoski/node-dsp
 

> 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
-----------------------------------------------------------