From 20a46aacb59a8b01612ae4ea2a826153dc19bdc7 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 b74da44ce0..d5f661756f 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 {