From 959f0a2204822a5eac8d8186e585ae196c820495 Mon Sep 17 00:00:00 2001 From: shirakaba <14055146+shirakaba@users.noreply.github.com> Date: Wed, 21 Dec 2022 21:42:31 +0900 Subject: [PATCH] fix: swap spread for slice --- packages/core/data/dom-events/dom-event.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/core/data/dom-events/dom-event.ts b/packages/core/data/dom-events/dom-event.ts index 6cd8f09da..3c49d499a 100644 --- a/packages/core/data/dom-events/dom-event.ts +++ b/packages/core/data/dom-events/dom-event.ts @@ -365,8 +365,14 @@ export class DOMEvent implements Event { // Taking multiple params instead of a single property bag saves 250 // nanoseconds per dispatchTo() call. private handleEvent(data: EventData, isGlobal: boolean, phase: 0 | 1 | 2 | 3, removeEventListener: (eventName: string, callback?: any, thisArg?: any, capture?: boolean) => void, removeEventListenerContext: unknown) { - // Clone the array just before any mutations. - const listeners = [...this.listeners]; + // Clone the array just before any mutations. I tried swapping this out + // for a copy-on-write array, but as it had to maintain its own array of + // listeners for any write actions, it actually ran significantly + // slower. + // + // There's no clear observable difference between array spread and slice + // here, but I think slice has reason to run faster. + const listeners = this.listeners.slice(); for (let i = listeners.length - 1; i >= 0; i--) { const listener = listeners[i];