perf(core): use native addEventListener for faster rendering. (#18107)
Angular can make many assumptions about its event handlers. As a result the bookkeeping for native addEventListener is significantly cheaper than Zone's addEventLister which can't make such assumptions. This change bypasses the Zone's addEventListener if present and always uses the native addEventHandler. As a result registering event listeners is about 3 times faster. PR Close #18107
This commit is contained in:

committed by
Miško Hevery

parent
8bcb268140
commit
6279e50d78
@ -172,7 +172,8 @@ class DefaultServerRenderer2 implements Renderer2 {
|
||||
const el =
|
||||
typeof target === 'string' ? getDOM().getGlobalEventTarget(this.document, target) : target;
|
||||
const outsideHandler = (event: any) => this.ngZone.runGuarded(() => callback(event));
|
||||
return this.ngZone.runOutsideAngular(() => getDOM().onAndCancel(el, eventName, outsideHandler));
|
||||
return this.ngZone.runOutsideAngular(
|
||||
() => getDOM().onAndCancel(el, eventName, outsideHandler) as any);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user