Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checkpoints during replay #6

Closed
Yuyz0112 opened this issue Dec 14, 2018 · 7 comments
Closed

Add checkpoints during replay #6

Yuyz0112 opened this issue Dec 14, 2018 · 7 comments

Comments

@Yuyz0112
Copy link
Member

We need to improve the 'play at any time' feature which supports rrweb-player's DND interactions.

Currently, we do this by introducing sync mode which will rebuild snapshot before time offset synchronously and then play under the timer. But this may cause a performance issue when we try to play at a large time offset.

For example, if we have 100 snapshots and we play in the third snapshot's time offset, we need to rebuild 3 snapshots synchronously which is fine. When we are trying to play at the 99th snapshot's time offset, we need to rebuild 99 snapshots synchronously which will block everything.

So the solution is to build checkpoints when we create a replayer. We may cache the result of rebuilding every 50 snapshots, so the maximize synchronously snapshots rebuilding number is 50.

@DvdGiessen
Copy link
Contributor

When this is being refactored, it might be valuable to separate three distinct concepts here?

Right now we have the "storage of events", which are then converted in "playback" actions, which are then executed by timing logic. However, these three are tightly integrated, which makes it a bit hard to use one of the specific elements but not the others.

In the current code, replay/timer.ts is both concerned with storing a list of actions, and timing their playback, while replay/index.ts mostly handles generating actions which modify a output iframe but is also dependant on certain timer functions.

For example for the case of live streaming it'd be nice if I was able to reuse the event storage and playback action generation, but supply my own timing logic. Or, another example, if I wanted to output to multiple iframes, I'd like to still use the event store but have multiple replay functions use it. I'm also interested in allowing the use of a more abstracted clock for the timing logic so that other time-bound elements may tie in to it.

Splitting the concepts up might look like this:

  • Event store: Just stores the events. It may do some preprocessing, but it isn't directly concerned with actually replaying anything. It provides a method to add events, and one to retrieve events between two timestamps, and probably an emitter to notify other objects its contents have been updated.
  • Replay renderer: Only handles actual replaying of events, doesn't store them or determine when they should be replayed. Is given an output element and an event store, and provides a single method render(time: number) which renders the replay in its output element for the given timestamp.
  • Timer loop: A requestAnimationFrame loop which calls the render(time: number) method of the replay renderer to actually make it play back. This would then also be the only part to be connected to the playback controls in the interface.

The event store would then be the place where these checkpoints (which would basically be full snapshots) are (pre)computed, so that it can return a small number of events for the replay rendererer to render to go to a certain point in time.

The replay renderer should remember the last timestamp it rendered, and only request a delta from that timestamp instead of having to render from the very first full snapshot. It might also do some higher level caching by storing a clones of rendered snapshots so it won't have to reconstruct them.

I know this is only laterally related to this issue, but it might be useful to think about before effort is put into building the checkpoint logic so that if this is something we'd like and want to consider, one can somewhat account for it while tackling this issue.

@remisharrock
Copy link

Could you try the CODECAST player scrolling https://codecast.wp.imt.fr/codecast/ maybe you can find a way to have fast scrolling to any point in time in the source code https://github.com/France-ioi/codecast ?

@Yuyz0112
Copy link
Member Author

@remisharrock Thanks, I'll take a look.

@remisharrock
Copy link

I found the name of the library that enables the fast seeking through the recording: Redux-Saga, as you can see in this file : https://github.com/France-ioi/codecast/blob/master/frontend/player/sagas.js
It says that

// An instant has shape {t, eventIndex, state},
// where state is an Immutable Map of shape

My guess is that the shape could be a VirtualDOM ?
Also the code has a lot of synchronization with the audio being played simultaneously.

By the way, you can try the recorder here https://codecast.france-ioi.org/v6/recorder by clicking the "guest" button , authorizing the use of your microphone, clicking the record button (red "start recording" and by typing some code in the editor (also selecting text, scrolling, compiling if it's C code and executing step by step etc...)

Interesting here: when you click the pause button you can go back a little bit in the recording and start from this point.

Another thing interesting here: when you click the stop button, the audio is being compressed to mp3 client-side (using a javascript mp3 encoding library) ;

Finally, when you click the save button, the JSON containing the events and the mp3 file is being sent to a server and you can play back the recording using the generated URL (playback link).

Can you try it and tell me what you think ?

Also try to seek during playback and also drag and drop the time cursor, you will see immediate changes, which I think is pretty cool ;)

Hope that you can find a good solution from this project, in order to have this kind of reactivity when you seek through the recording during playback !

@remisharrock
Copy link

remisharrock commented May 18, 2019

Also it looks like another dev has a slightly more updated CODECAST project (forked) and is working on it right now here: https://github.com/pkrll/codecast

@remisharrock
Copy link

Any news on checkpointing or an approach to fast forward in any point in time very fast?

@buremba
Copy link

buremba commented May 5, 2020

This would be a great feature IMO. We plan to use rrweb for product demos and definitely take advantage of it.

Yuyz0112 added a commit that referenced this issue Jul 11, 2020
related to #6

Since the currently 'play at any time offset' implementation is pretty simple,
there are many things we can do to optimize its performance.

In this patch, we do the following optimizations:
1. Ignore some of the events during fast forward.
   For example, when we are going to fast forward to 10 minutes later,
   we do not need to perform mouse movement events during this period.
2. Use a fragment element as the 'virtual parent node'.
   So newly added DOM nodes will be appended to this fragment node,
   and finally being appended into the document as a batch operation.
These changes reduce a lot of time which was spent on reflow/repaint previously.
I've seen a 10 times performance improvement within these approaches.

And there are still some things we can do better but not in this patch.
1. We can build a virtual DOM tree to store the mutations of DOM.
   This will minimize the number of DOM operations.
2. Another thing that may help UX is to make the fast forward process async and cancellable.
   This may make the drag and drop interactions in the player's UI looks smooth.
Yuyz0112 added a commit that referenced this issue Jul 11, 2020
related to #6

Since the currently 'play at any time offset' implementation is pretty simple,
there are many things we can do to optimize its performance.

In this patch, we do the following optimizations:
1. Ignore some of the events during fast forward.
   For example, when we are going to fast forward to 10 minutes later,
   we do not need to perform mouse movement events during this period.
2. Use a fragment element as the 'virtual parent node'.
   So newly added DOM nodes will be appended to this fragment node,
   and finally being appended into the document as a batch operation.
These changes reduce a lot of time which was spent on reflow/repaint previously.
I've seen a 10 times performance improvement within these approaches.

And there are still some things we can do better but not in this patch.
1. We can build a virtual DOM tree to store the mutations of DOM.
   This will minimize the number of DOM operations.
2. Another thing that may help UX is to make the fast forward process async and cancellable.
   This may make the drag and drop interactions in the player's UI looks smooth.
Yuyz0112 added a commit that referenced this issue Jul 11, 2020
related to #6

Since the currently 'play at any time offset' implementation is pretty simple,
there are many things we can do to optimize its performance.

In this patch, we do the following optimizations:
1. Ignore some of the events during fast forward.
   For example, when we are going to fast forward to 10 minutes later,
   we do not need to perform mouse movement events during this period.
2. Use a fragment element as the 'virtual parent node'.
   So newly added DOM nodes will be appended to this fragment node,
   and finally being appended into the document as a batch operation.
These changes reduce a lot of time which was spent on reflow/repaint previously.
I've seen a 10 times performance improvement within these approaches.

And there are still some things we can do better but not in this patch.
1. We can build a virtual DOM tree to store the mutations of DOM.
   This will minimize the number of DOM operations.
2. Another thing that may help UX is to make the fast forward process async and cancellable.
   This may make the drag and drop interactions in the player's UI looks smooth.
YunFeng0817 pushed a commit that referenced this issue Mar 19, 2023
lewgordon-amplitude added a commit to lewgordon-amplitude/rrweb that referenced this issue Aug 1, 2024
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

No branches or pull requests

4 participants