Open Bug 730712 Opened 13 years ago Updated 3 years ago

Don't use do_CreateInstance() in canvas.getContext()

Categories

(Core :: Graphics: Canvas2D, defect)

defect

Tracking

()

UNCONFIRMED

People

(Reporter: cers, Unassigned)

Details

canvas.getContext("2d") in Firefox is about 7 times slower than it is in Chrome. You can see this difference by running the test here in both Firefox and Chrome: http://jsperf.com/getcontext (Firefox can't run the second test as it requires an argument to be passed to getContext, whereas Chrome seems to default to "2d" - from the spec, I'd say we're probably in the right here) Ms2ger mentioned in #developers that the implementation shouldn't be using do_CreateInstance (which it currently is).
So I did a profile of a testcase basically similar to the one linked to. The do_CreateInstance cost is not showing up at all, not surprisingly: we only pay that cost on the very first getContext call on a given canvas. Close to 64% of the time is spent in the slow path of "get a JS object for a C++ object". Wrappercaching the 2d context would almost certainly help here. Not sure whether it's worth doing that before new DOM bindings. There are also other things that would help (having a de-COMed call here and whatnot) that once again DOM bindings would help with. Even then we're likely to end up with some of the current costs (e.g. the fact that addref/release on a 2d context have to hit the cycle collector). :( So if people want to try to eliminate the do_CreateInstance call that's fine, but it won't help performance on the linked testcase any.
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.