From c19aaa7ec0561af8ff18dd198ef03dbc10b74659 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] Only execute events since most recent pageload when playing from an offset (#200) On recordings with many full pageloads, dom state and mutations were being applied only to be discarded when a new pageload came in, resulting in very slow time to rebuild - and inability to interactively 'scrub' through these recordings --- src/replay/machine.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/replay/machine.ts b/src/replay/machine.ts index 936ffb33..24ea012a 100644 --- a/src/replay/machine.ts +++ b/src/replay/machine.ts @@ -4,6 +4,7 @@ import { eventWithTime, actionWithDelay, ReplayerEvents, + EventType, Emitter, } from '../types'; import { Timer, getDelay } from './timer'; @@ -169,8 +170,22 @@ export function createPlayerService( play(ctx) { const { timer, events, baselineTime, lastPlayedEvent } = ctx; timer.clear(); - const actions = new Array(); + const needed_events = new Array(); for (const event of events) { + if (event.timestamp < baselineTime && + event.type === EventType.FullSnapshot && + needed_events.length > 0 && + needed_events[needed_events.length -1].type === EventType.Meta + ) { + // delete everything before Meta + // so that we only rebuild from the latest full snapshot + needed_events.splice(0, needed_events.length -1); + } + needed_events.push(event); + } + + const actions = new Array(); + for (const event of needed_events) { if ( lastPlayedEvent && (event.timestamp <= lastPlayedEvent.timestamp ||