♻️ [PANA-5948] Make some small improvements to ItemId management #4164
+63
−8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
ItemIdsinterface, which is used to track the identifiers assigned to various kinds of DOM-related objects during recording.In particular:
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.nextIdgetter 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.clear()method now does nothing if no ids have been assigned. This is just a small performance optimization.Related code has been updated:
startFullSnapshots.ts, we now always callscope.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 nowItemIds#clear()avoids the unnecessary work automatically.recordingScope.ts, the implementation ofscope.resetIds()now callsclear()on theItemIdsinstances that are currently stored on theRecordingScope, instead of just the ones that were passed in when theRecordingScopewas constructed. This is helpful for testing the new serialization algorithm, since it allows us to wrap theseItemIdsinstance in test code with version that check assertions.clear()is not visible, so there's no test, but the existing tests continue to pass.)Checklist