Skip to content

Commit

Permalink
ref: Avoid cloning events to add timestamp
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mydea committed Oct 25, 2023
1 parent 8444cb2 commit 065587a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-colts-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb': patch
---

ref: Avoid cloning events to add `timestamp`
7 changes: 3 additions & 4 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,9 @@ import {
} from './error-handler';

function wrapEvent(e: event): eventWithTime {
return {
...e,
timestamp: nowTimestamp(),
};
const eWithTime = e as eventWithTime;
eWithTime.timestamp = nowTimestamp();
return eWithTime;
}

let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void;
Expand Down

0 comments on commit 065587a

Please sign in to comment.