Skip to content

Conversation

@sethfowler-datadog
Copy link
Contributor

Motivation

Change records are a new, experimental data format for session replay data that's designed to record the same information in a more compact, more compressible form.

We've already landed support for recording full snapshots as Change records behind an experiment flag. The next step is to introduce support for incremental snapshots, as well. This requires making improvements to a number of different aspects of the recording code. This PR is the second in a series that will work toward the goal of supporting incremental snapshots; for the previous PR, see #4163.

Changes

This PR makes some small improvements to the code surrounding the ItemIds interface, which is used to track the identifiers assigned to various kinds of DOM-related objects during recording.

In particular:

  1. A delete() method has been added, making it possible to delete an item id. This allows you to reinsert the same item and assign it a new id, which is something that the new serialization algorithm requires.
  2. A nextId getter has been added, making it possible to determine what the next item id will be before actually assigning it. This, too, is helpful for implementing the new serialization algorithm.
  3. The existing clear() method now does nothing if no ids have been assigned. This is just a small performance optimization.

Related code has been updated:

  1. In startFullSnapshots.ts, we now always call scope.resetIds() when generating a Change record, regardless of whether we're generating the initial full snapshot or a subsequent one. We avoided calling it for the first full snapshot as a small performance optimization, but now ItemIds#clear() avoids the unnecessary work automatically.
  2. In recordingScope.ts, the implementation of scope.resetIds() now calls clear() on the ItemIds instances that are currently stored on the RecordingScope, instead of just the ones that were passed in when the RecordingScope was constructed. This is helpful for testing the new serialization algorithm, since it allows us to wrap these ItemIds instance in test code with version that check assertions.
  3. Tests have been added for the new methods. (The behavior change in clear() is not visible, so there's no test, but the existing tests continue to pass.)

Checklist

  • Tested locally
  • Tested on staging
  • Added unit tests for this change.
  • Added e2e/integration tests for this change.
  • Updated documentation and/or relevant AGENTS.md file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant