Closed Bug 1843484 Opened 1 year ago Closed 1 year ago

Avoid QueryInterface to convert nsINode to EventTarget in EventDispatcher::Dispatch and friends

Categories

(Core :: DOM: Events, task)

task

Tracking

()

RESOLVED FIXED
119 Branch
Tracking Status
firefox119 --- fixed

People

(Reporter: mstange, Assigned: mstange)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sp3])

Attachments

(4 files)

nsINode inherits from mozilla::dom::EventTarget.

However, both EventDispatcher::Dispatch and nsContentUtis::DispatchEvent use nsISupports* for their event target argument. Then they convert this nsISupports into a mozilla::dom::EventTarget with a QueryInterface:

nsCOMPtr<EventTarget> target = do_QueryInterface(aTarget);

So when we want to dispatch an event on an nsINode, we pay the QueryInterface cost even though the conversion is trivial.

This shows up noticeably in the testcases in bug 1834003: https://share.firefox.dev/3Oe7Jd5

The funniest part is that nsContentUtils::DispatchEvent does a QueryInterface, and then calls EventDispatcher::DispatchDOMEvent which calls EventDispatcher::Dispatch which does another QueryInterface.

We should change all these methods to accept the aTarget parameter as a mozilla::dom::EventTarget*. It should be the caller's responsibility to do the type conversion.

Assignee: nobody → mstange.moz
Status: NEW → ASSIGNED

thods. r=smaug

This saves a few queryInterface calls on the hot path.

Depends on D186976

Attachment #9350527 - Attachment description: WIP: Bug 1843484 - Use EventTarget* instead of nsISupports* for the event target parameter of the EventDispatcher::Dispatch me → Bug 1843484 - Use EventTarget* instead of nsISupports* for the event target parameter of the EventDispatcher::Dispatch methods. r=smaug
Pushed by mstange@themasta.com:
https://hg.mozilla.org/integration/autoland/rev/dbe2251dd9b2
Use EventTarget* instead of nsISupports* for the event target parameter of the nsContentUtils::Dispatch methods. r=smaug
https://hg.mozilla.org/integration/autoland/rev/688628005eae
Use EventTarget* instead of nsISupports* for the event target parameter of the EventDispatcher::Dispatch methods. r=smaug
https://hg.mozilla.org/integration/autoland/rev/8031bd3adbe3
Use EventTarget* instead of nsISupports* in some nsFocusManager methods. r=smaug
https://hg.mozilla.org/integration/autoland/rev/74ca256e1cb6
Don't hold an extra strong reference to the event target. r=smaug
Regressions: 1850458
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: