Skip to content

Commit

Permalink
perf: Avoid an extra function call and object clone during event emis…
Browse files Browse the repository at this point in the history
…sion (rrweb-io#1441)

performance: remove a nested function call and an object clone during event emission

 - rename `event` to `eventWithoutTime`, but maintain backwards compatibility
 - `eventWithTime` (with time) could be renamed to `event` in a future version

This is an extension of PR rrweb-io#1339 authored by: mydea <mydea@users.noreply.github.com>
  • Loading branch information
eoghanmurray authored and jxiwang committed Oct 16, 2024
1 parent 05a7d35 commit b996cbb
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 177 deletions.
5 changes: 5 additions & 0 deletions .changeset/event-single-wrap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'rrweb': patch
---

perf: Avoid an extra function call and object clone during event emission
6 changes: 3 additions & 3 deletions packages/rrweb/src/record/iframe-manager.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Mirror, serializedNodeWithId } from '@amplitude/rrweb-snapshot';
import { NodeType, genId } from '@amplitude/rrweb-snapshot';
import type { eventWithTime, mutationCallBack } from '@amplitude/rrweb-types';
import type { eventWithTime, eventWithoutTime, mutationCallBack } from '@amplitude/rrweb-types';
import { EventType, IncrementalSource } from '@amplitude/rrweb-types';
import type { CrossOriginIframeMessageEvent } from '../types';
import CrossOriginIframeMirror from './cross-origin-iframe-mirror';
Expand All @@ -16,7 +16,7 @@ export class IframeManager {
new WeakMap();
private mirror: Mirror;
private mutationCb: mutationCallBack;
private wrappedEmit: (e: eventWithTime, isCheckout?: boolean) => void;
private wrappedEmit: (e: eventWithoutTime, isCheckout?: boolean) => void;
private loadListener?: (iframeEl: HTMLIFrameElement) => unknown;
private stylesheetManager: StylesheetManager;
private recordCrossOriginIframes: boolean;
Expand All @@ -26,7 +26,7 @@ export class IframeManager {
mutationCb: mutationCallBack;
stylesheetManager: StylesheetManager;
recordCrossOriginIframes: boolean;
wrappedEmit: (e: eventWithTime, isCheckout?: boolean) => void;
wrappedEmit: (e: eventWithoutTime, isCheckout?: boolean) => void;
}) {
this.mutationCb = options.mutationCb;
this.wrappedEmit = options.wrappedEmit;
Expand Down
Loading

0 comments on commit b996cbb

Please sign in to comment.