addPath with a DOMMatrix is slow
Categories
(Core :: Graphics: Canvas2D, defect)
Tracking
()
Tracking | Status | |
---|---|---|
firefox139 | --- | fixed |
People
(Reporter: calixte, Assigned: smaug)
Details
Attachments
(2 files)
With the attached test case, 90% of the time is spent in just initializing the matrix:
https://share.firefox.dev/44cvmLp
Maybe it could be interesting to allow a Float(32|64)Array for the second parameter or six numbers (i.e. addPath(path, a, b, c , d, e, f)).
Assignee | ||
Comment 1•15 days ago
•
|
||
Oh, the testcase passes DOMMatrix as input, function is defined to take DOMMatrix2DInit as input. And getting the data out of native implementation is slower than it would be to get it from normal dictionary.
If we could detect earlier that it is a real DOMMatrix, then this should be faster.
Though, on JS side one could override the normal getters, I think, and those should get called.
Assignee | ||
Comment 2•15 days ago
|
||
Calixte, in your code, would it be possible to use a simple dictionary and does that improve performance?
addPath(path, { a: 123, b: 345, .... })
Assignee | ||
Comment 3•15 days ago
|
||
Lots of time is spent also in creating (temporary?) DOMMatrix internally
https://searchfox.org/mozilla-central/rev/a0c761cb7958c0c9a3e7e34d944f12b56e0737fa/dom/canvas/CanvasRenderingContext2D.cpp#7088-7089
Kagami, do you recall why it was implemented that way? Does something require us creating that seemingly temporary object?
This is a hot code path, so any extra allocations should be avoided if possible
Comment 4•15 days ago
|
||
It's the spec: https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d-addpath
Let matrix be the result of creating a DOMMatrix from the 2D dictionary transform.
Might be nice to have a struct than a full blown DOMMatrix though.
Assignee | ||
Comment 5•15 days ago
|
||
Well, specs algorithms do all sorts of extra things just to make it easier to define things on that side. Implementation need to optimize.
But ok, sounds like we could just have a stack allocated struct.
Reporter | ||
Comment 6•15 days ago
|
||
(In reply to Olli Pettay [:smaug][bugs@pettay.fi] from comment #2)
Calixte, in your code, would it be possible to use a simple dictionary and does that improve performance?
addPath(path, { a: 123, b: 345, .... })
Interesting, yes it's a way faster, either in pdf.js or with the test case above.
Assignee | ||
Comment 7•15 days ago
|
||
Updated•15 days ago
|
Comment 9•12 days ago
|
||
bugherder |
Description
•