[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 5:07 PM, Rik Cabanier <cabanier@gmail.com> wrote:
>
>
> On Thu, Mar 21, 2013 at 4:14 PM, Kenneth Russell <kbr@google.com> wrote:
>>
>> On Thu, Mar 21, 2013 at 4:01 PM, Gregg Tavares <gman@google.com> wrote:
>> >
>> >
>> >
>> > On Thu, Mar 21, 2013 at 3:27 PM, Rik Cabanier <cabanier@gmail.com>
>> > wrote:
>> >>
>> >>
>> >>
>> >> On Thu, Mar 21, 2013 at 3:18 PM, Rik Cabanier <cabanier@gmail.com>
>> >> 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.
>> >>>
>> >>>
>> >>> You constructed 2 temporaries there as well as brought in at least 12
>> >>> floats into the JS VM + you did all the math in js.
>> >>
>> >>
>> >> I take that back. There's also only 1 temporary.
>> >>
>> >> Can the VM create native code for typed arrays?
>> >
>> >
>> > AFAIK both Firefox and Chrome are working on making the VM create native
>> > code for typed arrays.
>>
>> What does "creating native code for typed arrays" mean exactly?
>
>
> Let's say you have a function that multiplies 2 arrays.
>
> Can the interpreter generate native code if the signature is like this:
>
> function mul(Float32Array a, Float32Array b) {
>
> return new Float32Array(a[0]*b[0]+..., ...)
>
> }
>
> I know it can if you pass 2 objects [1]
>
> function mul(Matrix a, Matrix b) {
>
> var c = new Matrix;
> c.a = a.a * b.a + ...;
> ...
>
> }

Yes, the dynamic compiler will generate native code for the function.

As I mentioned, in Chrome right now, typed array allocation is slow,
but this is being actively worked on. (The indexing operations,
however, are already extremely fast.) When the work is complete,
allocating typed arrays will be as cheap as allocating any other
JavaScript object.

-Ken


> 1: http://www.youtube.com/watch?v=UJPdhx5zTaw
>
>
>
>>
>>
>> Chrome, Firefox and Safari already heavily optimize typed array
>> getters and setters in their JavaScript-to-native-code dynamic
>> compilers. This is why demonstrations like
>>
>> https://www.khronos.org/registry/webgl/sdk/demos/google/nvidia-vertex-buffer-object/
>> run so quickly.
>>
>> 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.
>>
>> -Ken
>>
>>
>> >> I though that only worked if you used objects.
>> >>
>> >>>
>> >>>
>> >>>  If 'element.style.transform' returned a live object, you could just
>> >>> do
>> >>> 'element.style.transform.rotateBy(45)' and have only 1 temporary.
>> >>>
>> >>
>> >
>
>

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