From 118362f0ba2a43ab5a709347022a64bb5de5a154 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Wed, 25 Oct 2023 13:28:11 +0200 Subject: [PATCH] ref: Avoid cloning events to add `timestamp` We are always passing in fresh objects to this method, so instead of cloning this into a new object, we can just put the `timestamp` on the given object directly and return it, saving a bit of processing cost. --- packages/rrweb/src/record/index.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/rrweb/src/record/index.ts b/packages/rrweb/src/record/index.ts index c5fc3ed580..09f786f58e 100644 --- a/packages/rrweb/src/record/index.ts +++ b/packages/rrweb/src/record/index.ts @@ -53,10 +53,9 @@ import { } from './error-handler'; function wrapEvent(e: event): eventWithTime { - return { - ...e, - timestamp: nowTimestamp(), - }; + const eWithTime = e as eventWithTime; + eWithTime.timestamp = nowTimestamp(); + return eWithTime; } declare global {