Contact emails
jinho...@samsung.com, caba...@adobe.com, dsch...@chromium.org
Spec
http://dev.w3.org/fxtf/geometry/
Summary
The specification provides basic geometric interfaces to represent points, rectangles,
quadrilaterals and transformation matrices that can be used by other modules or specifications.
We will implement following things:
- DOMMatrix Interface
- DOMRect Interface
- DOMRectList Interface
- DOMQuad Interface
- DOMPoint interface
Motivation
The SVG interfaces SVGPoint, SVGRect and SVGMatrix are aliasing the here defined interfaces
in favor for common interfaces used by SVG, Canvas 2D Context and CSS Transforms.
Compatibility Risk
Low, These are already being implemented in Firefox and WebKit (Rik and Dirk)
Ongoing technical constraints
None
Will this feature be supported on all five Blink platforms (Windows, Mac, Linux, Chrome OS and Android)?
Yes
OWP launch tracking bug?
Link to entry on the feature dashboard
http://www.chromestatus.com/features/6015941766807552
Requesting approval to ship?
No
- DOMRectList Interface
Contact emails
jinho...@samsung.com, caba...@adobe.com, dsch...@chromium.org
Spec
http://dev.w3.org/fxtf/geometry/
Summary
The specification provides basic geometric interfaces to represent points, rectangles,
quadrilaterals and transformation matrices that can be used by other modules or specifications.
We will implement following things:
- DOMMatrix Interface
- DOMRect Interface
- DOMRectList Interface
- DOMQuad Interface
- DOMPoint interface
Motivation
The SVG interfaces SVGPoint, SVGRect and SVGMatrix are aliasing the here defined interfaces
in favor for common interfaces used by SVG, Canvas 2D Context and CSS Transforms.
Compatibility Risk
Low, These are already being implemented in Firefox and WebKit (Rik and Dirk)
Ongoing technical constraints
None
Will this feature be supported on all five Blink platforms (Windows, Mac, Linux, Chrome OS and Android)?
Yes
OWP launch tracking bug?
Link to entry on the feature dashboard
http://www.chromestatus.com/features/6015941766807552
Requesting approval to ship?
No
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
> I think the point Domenic is making is that the places that currently return DOMRectList should just return a sequence<DOMRect>.
Yes, exactly.
When I originally wrote the email, I wasn't aware that there are parts of the platform already making use of DOMRectList, since my impression this was an intent to implement new interfaces. It looks like at the least getClientRects does; does anyone else?
I see two paths forward:
- If implementers are willing to try it, converting to a real array (WebIDL "sequence") would be ideal and greatly improve the developer experience.
- If we don't want to spend the time testing such a change (which is understandable), then I'd recommend DOMRectList get [NoInterfaceObject], and rename it LegacyGetClientRectsReturnValueType or some such so that it gets hidden as far away from developers as possible, and so no spec uses it in the future.
On Wed, Jun 25, 2014 at 10:05 PM, Rik Cabanier <caba...@gmail.com> wrote:I'm not sure introducing a subclass of Array with item() is worth it
> Are you saying that we should replace the current API with a subclassed
> array class but only if this subclass will be used in other places?
for this specific legacy *List interface. But if we can replace a
bunch of them...
> Given this, maybe we should just stick with the current definition.
> If we decide later that it needs the additional array-like behavior, we can add it then.
The question is, do we ever expect developers to use this type? If so, we should fix it as soon as is feasible (i.e., as soon as browser ship ES6 built-in subclassing). If no new code uses getClientRects(), e.g. because getBoxQuads() is better, then I guess we can just leave it as another warty old API.
> I do agree with Dominic that we should make it a [NoInterfaceObject] object.
We should also ensure no other specs ever use this type, with an appropriately-scary name, and probably a note in the spec as well.
From: Rik Cabanier <caba...@gmail.com>
The question is, do we ever expect developers to use this type? If so, we should fix it as soon as is feasible (i.e., as soon as browser ship ES6 built-in subclassing). If no new code uses getClientRects(), e.g. because getBoxQuads() is better, then I guess we can just leave it as another warty old API.
> Given this, maybe we should just stick with the current definition.
> If we decide later that it needs the additional array-like behavior, we can add it then.
> I do agree with Dominic that we should make it a [NoInterfaceObject] object.We should also ensure no other specs ever use this type, with an appropriately-scary name, and probably a note in the spec as well.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
I am concerned about the performance of these APIs, particularly DOMMatrix.A javascript polyfill will be faster than the native DOMMatrix as it's implemented today. I do not think we should be dropping performance landmines for graphics developers to trip over, even at the cost of making the APIs more complex (e.g., taking typed arrays instead of slow objects).Is performance a concern?
Can we do something better on the implementation side?
On Tue, Aug 26, 2014 at 12:40 PM, Philip Rogers <p...@chromium.org> wrote:
I am concerned about the performance of these APIs, particularly DOMMatrix.A javascript polyfill will be faster than the native DOMMatrix as it's implemented today. I do not think we should be dropping performance landmines for graphics developers to trip over, even at the cost of making the APIs more complex (e.g., taking typed arrays instead of slow objects).Is performance a concern?It would be great to have some data on the performance. It's likely that crossing into the c++ side takes up more cycles than the actual implementation :-)Jinho did want to implement it using blink-in-javascript but had to abandon that idea since it doesn't support constructors.
Rik,I've now read the webkit [1] and mozilla [2] threads on this topic and it looks like these issues have been covered before. I do not think we should ship the geometry interfaces in Blink. DOMMatrix and friends will be slow in Blink for the same reasons WebKit balked at them [3]. As the blink-in-js docs [4] say, blink-in-js should not be used for high-performance apis like this. Maybe we can use typed arrays for these APIs instead?
An alternative is to implement and standardize these interfaces as first-class citizens in Ecmascript.
On Tue, Aug 26, 2014 at 3:01 PM, Philip Rogers <p...@chromium.org> wrote:
Rik,I've now read the webkit [1] and mozilla [2] threads on this topic and it looks like these issues have been covered before. I do not think we should ship the geometry interfaces in Blink. DOMMatrix and friends will be slow in Blink for the same reasons WebKit balked at them [3]. As the blink-in-js docs [4] say, blink-in-js should not be used for high-performance apis like this. Maybe we can use typed arrays for these APIs instead?Like you said, we covered that approach in the past. Typed arrays are not author friendly and will need additional JS libraries to make them useful.I also doubt that type arrays will be faster as the C++ side will now have to look into the JS VM to get the values out.DOMMatrix as currently proposed, is basically a drop-in replacement of the existing SVGMatrix class along with some extra methods and abstractions to address its shortcomings. (I noticed that we didn't add DOMMatrixInit to the spec yet. It's a dictionary with the attributes of DOMMatrix and will be used in methods that take a DOMMatrix as an argument)An alternative is to implement and standardize these interfaces as first-class citizens in Ecmascript.I believe Dirk looked into this and it didn't look encouraging.
I think we need hard data to see if there's actually a problem. I will try to run some tests and come back with results.
Rik,I've now read the webkit [1] and mozilla [2] threads on this topic and it looks like these issues have been covered before. I do not think we should ship the geometry interfaces in Blink. DOMMatrix and friends will be slow in Blink for the same reasons WebKit balked at them [3]. As the blink-in-js docs [4] say, blink-in-js should not be used for high-performance apis like this. Maybe we can use typed arrays for these APIs instead?
An alternative is to implement and standardize these interfaces as first-class citizens in Ecmascript.
On Tue, Aug 26, 2014 at 3:01 PM, Philip Rogers <p...@chromium.org> wrote:
Rik,I've now read the webkit [1] and mozilla [2] threads on this topic and it looks like these issues have been covered before. I do not think we should ship the geometry interfaces in Blink. DOMMatrix and friends will be slow in Blink for the same reasons WebKit balked at them [3]. As the blink-in-js docs [4] say, blink-in-js should not be used for high-performance apis like this. Maybe we can use typed arrays for these APIs instead?I wrote a small test case: http://jsperf.com/dommatrix-perfIt applies a typical translate/scale/rotate sequence to a DOMMatrix and a JS equivalent.Benchmarking this in Firefox Nightly (because the functionality is not in Chrome yet) shows that the JS implementation is 3 to 4 times faster. This is expected since crossing into the c++ side slows things down.To make a more realistic case, I added another test that calls setLineDash with the JS array to simulate a DOM crossing. I verified that the C++ side just verifies the contents of that array and stores it in the canvas state. That test is almost twice as slow as the DOMMatrix test.(I also tried typed arrays but they were slower than native JS arrays)This tells me that there is no performance problem with DOMMatrix.
In addition, jsperf reports that on my core i-7 3.4 GHz, I can do 360,000 translate/scale/rotate sequences per second.So, if I animate 100 objects simultaneously, DOMMatrix will only take up: 100 objects * 60fps / 360,0000 ops = 0.017s
On Wed Sep 03 2014 at 10:30:16 AM Rik Cabanier <caba...@gmail.com> wrote:
On Tue, Aug 26, 2014 at 3:01 PM, Philip Rogers <p...@chromium.org> wrote:
Rik,I've now read the webkit [1] and mozilla [2] threads on this topic and it looks like these issues have been covered before. I do not think we should ship the geometry interfaces in Blink. DOMMatrix and friends will be slow in Blink for the same reasons WebKit balked at them [3]. As the blink-in-js docs [4] say, blink-in-js should not be used for high-performance apis like this. Maybe we can use typed arrays for these APIs instead?I wrote a small test case: http://jsperf.com/dommatrix-perfIt applies a typical translate/scale/rotate sequence to a DOMMatrix and a JS equivalent.Benchmarking this in Firefox Nightly (because the functionality is not in Chrome yet) shows that the JS implementation is 3 to 4 times faster. This is expected since crossing into the c++ side slows things down.To make a more realistic case, I added another test that calls setLineDash with the JS array to simulate a DOM crossing. I verified that the C++ side just verifies the contents of that array and stores it in the canvas state. That test is almost twice as slow as the DOMMatrix test.(I also tried typed arrays but they were slower than native JS arrays)This tells me that there is no performance problem with DOMMatrix.3-4x slower seems like a performance problem...
In addition, jsperf reports that on my core i-7 3.4 GHz, I can do 360,000 translate/scale/rotate sequences per second.So, if I animate 100 objects simultaneously, DOMMatrix will only take up: 100 objects * 60fps / 360,0000 ops = 0.017sHow long does it take on a phone? Do you think the web platform can afford to give away 3-4x performance and still be competitive on mobile?
On 9/3/14, 5:35 PM, Rik Cabanier wrote:I doubt it's a bug in the JIT. It's the _native_ version that's slower on Windows, not the JS version! In any case, it's definitely a Windows-specific issue.
I talked to the mozilla people and this is a bug in the JIT in Firefox
for Windows.
On Mac and Linux, DOMMatrix is actually faster than the JS
implementation with no DOM interaction.
If you pass to a DOM method that expects a sequence<float>, sure: Gecko doesn't have a fast path for convering a Float32Array to a sequence<float> in the DOM bindings at the moment.I also added tests that use float arrays. They are about the same speed
as DOMMatrix as long as you don't interact with the DOM. As soon as you
cross the DOM, native JS is 4 to 5 times slower than DOMMatrix.
Can you benchmark this in Blink? Performance numbers from Firefox aren't relevant to deciding how we should structure our implementation.
I'm not sure I understand. From your table, "JS eq w/ FA" appears to be the fastest at dommatrix-perf/7, which is what I would expect.I'm not sure I understand how the "+ DOM" condition relates. You appear to be comparing against the "Native" condition, which doesn't do the same thing (e.g., it's missing the call to gl.uniform2fv). Wouldn't it be appropriate to compare "JS eq w/ FA + DOM" with "Native + DOM"?
In any case, now we're only talking about 1.3x, which doesn't seem like a big deal. We need to make the bindings faster so that there's less overhead to leaving the VM, but that work doesn't need to block DOMMatric.
On Thu, Sep 4, 2014 at 4:55 PM, Adam Barth <aba...@chromium.org> wrote:
In any case, now we're only talking about 1.3x, which doesn't seem like a big deal. We need to make the bindings faster so that there's less overhead to leaving the VM, but that work doesn't need to block DOMMatric.Yes, there seems to be a problem on the blink side.Running this benchmark, Firefox is about 3 times faster which can't be explained by just more efficient matrix math.
Can the native one use SSE or Neon?
Rik,People in this very thread believe "native is faster" and I couldn't blame someone for using DOMMatrix over glMatrix/Sylvester/etc when we've guided them there with our DOM interfaces. Users will quickly learn they have to write FastDOMMatrix libraries (or add .toDOMMatrix() to existing ones) which makes DOMMatrix little more than a tasty syntax sugar performance trap.
The canvas APIs on Android use Matrix; why does ours have to be inferior?
Your DOMMatrix performance numbers look much different than mine.(Chrome 39.0.2147.0 / OSX with Jinho's rotate patch applied)Javascript multiplySelf - 72,402,124 ops/sDOMMatrix multiplySelf - 3,079,299 ops/sJavascript rotateSelf - 14,340,176 ops/sDOMMatrix rotateSelf - 1,175,006 ops/sJavascript translateSelf - 86,842,312 ops/sDOMMatrix translateSelf - 2,869,811 ops/sJavascript scaleSelf - 85,933,628 ops/sDOMMatrix scaleSelf - 2,842,229 ops/s(these tests technically run two ops per loop)
On Thu, Sep 4, 2014 at 5:43 PM, Jinho Bang <jinho...@samsung.com> wrote:
2014년 9월 5일 금요일 오전 9시 12분 8초 UTC+9, Rik Cabanier 님의 말:On Thu, Sep 4, 2014 at 4:55 PM, Adam Barth <aba...@chromium.org> wrote:
In any case, now we're only talking about 1.3x, which doesn't seem like a big deal. We need to make the bindings faster so that there's less overhead to leaving the VM, but that work doesn't need to block DOMMatric.Yes, there seems to be a problem on the blink side.Running this benchmark, Firefox is about 3 times faster which can't be explained by just more efficient matrix math.I believe Native implementation can be faster than JS implementation(in the jsperf test) because they are not full equivalent.Actual JS implementation should consider more things such as function overloading, exception handling and so on. therefore it can be slow than now.However, we still need to improve bindings.
On Fri, Sep 5, 2014 at 3:34 PM, Philip Rogers <p...@chromium.org> wrote:Rik,People in this very thread believe "native is faster" and I couldn't blame someone for using DOMMatrix over glMatrix/Sylvester/etc when we've guided them there with our DOM interfaces. Users will quickly learn they have to write FastDOMMatrix libraries (or add .toDOMMatrix() to existing ones) which makes DOMMatrix little more than a tasty syntax sugar performance trap.The whole point of DOMMatrix is to interact with the object that live on the C++ side. Your tests never cross the boundary so they are not how DOMMatrix would be used in the real world.
Moreover, most (all?) graphics libraries offer a matrix abstraction. It would be terrible if the web platform forces authors to write their own or download additional libraries to handle matrices in SVG, Canvas and CSS. (Rational platform etc)
DOMMatrix does have a conversion method to go to a floatArray but that will likely be slow. Maybe we can provide a get/setFloatArray method?The canvas APIs on Android use Matrix; why does ours have to be inferior?What canvas API on Android are you referring to? WebGL?Your DOMMatrix performance numbers look much different than mine.(Chrome 39.0.2147.0 / OSX with Jinho's rotate patch applied)Javascript multiplySelf - 72,402,124 ops/sDOMMatrix multiplySelf - 3,079,299 ops/sJavascript rotateSelf - 14,340,176 ops/sDOMMatrix rotateSelf - 1,175,006 ops/sJavascript translateSelf - 86,842,312 ops/sDOMMatrix translateSelf - 2,869,811 ops/sJavascript scaleSelf - 85,933,628 ops/sDOMMatrix scaleSelf - 2,842,229 ops/s(these tests technically run two ops per loop)You're basically testing DOM performance. What happens if you try to use those matrices?
Rik,
It may have gotten lost in all of my complaining, but I do support these interfaces in general. My issue is only with the performance in implementations.
Rik,
Yes, an alternative is to implement and standardize these interfaces as first-class citizens in Ecmascript.
Rik,
If we want to use a DOMMatrix in the DOM, we have to cross the bindings layer at least once. The current implementation crosses this boundary for every math operation, but in theory it only needs to for the setters/getters.
I thought these interfaces were primarily for non-live "dead simple?" objects and any liveness was only for backwards compatibility. Is that not the case?
Without live updating, there is a performance benefit to keeping the data in JS.
Are there dependent specs with new geometry APIs that have live requirements?
We should not be adding new live geometry APIs because they are slow-by-default. It's possible to build LiveDOMRect polyfills on static DOMRect and vice-versa; new APIs should be the fast-by-default versions (not live). Live APIs are slower, more complex, and difficult to implement properly (see the never ending SVG DOM security and stability issues).
I'm sympathetic to keeping live APIs in backwards-compat cases. My new year's wishlist has fast geometry objects implemented in V8, non-live APIs for using them (except in backwards-compat cases), and a unified set of interfaces that work across SVG and CSS.
On Thu, Oct 30, 2014 at 10:52 PM, Rik Cabanier <caba...@gmail.com> wrote:
> I do think that authors like live objects so we should't shut the door on
> having such APIs in the future.
Is that actually true?
Feedback on the DOM has been pretty constant in
asking for less "liveness". Live data structures are quite a bit
harder to reason about.
On Thu, Oct 30, 2014 at 3:52 PM, Anne van Kesteren <ann...@annevk.nl> wrote:On Thu, Oct 30, 2014 at 10:52 PM, Rik Cabanier <caba...@gmail.com> wrote:
> I do think that authors like live objects so we should't shut the door on
> having such APIs in the future.
Is that actually true?I don't have hard data on this.For instance, if you get an element from the DOM, you can just change it.You don't have to get it, change it and then replace the old one.
If you were new to javascript, it would be natural for you to use the same matrix class for everything.
V8 Extras:
https://docs.google.com/presentation/d/1Jgk6ymWooNYStTP11F_z9ajk3ezLgQqrGkdQTxE4xT0/mobilepresent?slide=id.gc6fa3c898_0_0
Hi Jinho! I'm glad you found the talk helpful. I agree that the geometry interfaces seem like a pretty ideal case where V8 extras can help.
It's not going to be trivial; in addition to the rough edges around debugging that I'm still working through, I can see a couple issues that will be a bit tricky:
- Making sure to match IDL semantics without the help of the binding generator. Thankfully the geometry spec does not have many requirements here; the use of `unrestricted double` everywhere is great because it means you can just use normal JS numbers with no conversion necessary.
- Integration into the bindings so that other Web IDL-implemented APIs can easily return DOMPoints etc., despite DOMPoint etc. not being defined in IDL. Streams is going through a similar thing and I'd be happy to work with you on making sure our solutions align.
I'd encourage starting with the simpler types (DOMPointReadOnly and DOMPoint) and once we get through those it'll hopefully be smooth sailing for the rest. I'd be happy to be looped in on any code reviews or answer any questions you have.