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

prefetching #442

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open

prefetching #442

wants to merge 29 commits into from

Conversation

interim17
Copy link
Contributor

@interim17 interim17 commented Jan 30, 2025

Time Estimate or Size

large
fix for lint warnings in another open PR

Problem

Prefetching frames is continuation of caching upgrades, and necessary for front end features like buffering indicators and playback speed settings.

Solution

Conceptually, we are establishing a distinction between the "playback head" and the "streaming head", which will get fleshed out with more complex caching behavior, some forthcoming Octopus adjustments, and the ability to move in and out of live mode.

I'm keeping controller method names and functionality intact to avoid breaking changes. That said, I have some opinions about some practices I'd like to move away from, primarily that I'd like to request frames, and use frame number, whenever possible, in preference over using simulation time. If the PR doesn't make it clear why, or if anyone disagrees, I am happy to discuss!

CacheAndStreamingLogs

This component may not need to be a permanent part of the test-bed, could be deleted/retired once some critical caching work is done, along with its callback. But for now getting some detailed readouts from the cache are essential for dev quality of life. Production front ends don't need to subscribe to the cache logs if they are unneeded, and the test bed readout is hidden until revealed. Better design/appearance TBD. Also changes to the recording component are just to save some visual space.

totalDuration / totalSteps and the general frame vs time issue

Time values like totalDuration in the test bed are derived from totalSteps and the timeStep. When we use a time value to request frames from the backend, we first have to derive it from frame number, and then Octopus has to convert it back into a frame number. Using this type of derived value for elements like the slider adds floats where we could be dealing with ints and potential front end back end sync issues. I think we should move away from calling gotoTime and towards using the new movePlaybackFrame. The functionality of gotoTime has been retained.

playing/streaming states and methods

Playback tracked via isPlaying instead of isPaused and both states held at controller level.
Some functions related to playback have been retained with the same naming (resume/pause) although I would like to make them more explicit in the future like: pausePlayback or even pausePreComputedSim and pauseLiveSim as we distinguish playback modes.

onStreamingChange

To subscribe the front end to changes in when we are streaming or not

onCacheUpdate

Subscribe the front end to logging from the cache, need is dev only for now, so currentStreamingHead is distinguished in visData as the piece necessary for production

getFrameAtTime

gotoTime is still a thing, as is simulator.requestFrameByTime but under the hood gotoTime is routed through this function, and then to movePlaybackFrame. When calling gotoTime the simulator does not actually request a frame by time.

remoteStreamingHeadPotentiallyOutOfSync

The async nature of our websocket stream leaves the small possibility that the viewer and the backend get out of sync in terms of what the "current" frame is in cases when when a frame has been rejected due to cache limit being reached.

This code to handle this behavior without major issues, but a long term fix to this is coming, as we will update Octopus messaging to include the ability to reset the backend's "current frame" without requesting a frame (currently the only way to do that).

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Steps to Verify:

  1. In the test bed you can inspect the state of playback, streaming, and caching on the Show cache and streaming info button. The current default will cache about 15 frames of the COVID trajectory which is my usually test trajectory. Try playing, pausing, and advancing/retreating frames.
  2. The cache limit is set via a prop on the Viewer, try different limits.
  3. When playing through cached frames you should see a very rapid and smooth playback, that turns slow and stepwise when displaying a live stream.

…r instead of time, callbacks for streaming changes
Copy link

github-actions bot commented Jan 30, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 24.94% 2748 / 11015
🔵 Statements 24.94% 2748 / 11015
🔵 Functions 26.43% 161 / 609
🔵 Branches 80.76% 361 / 447
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
examples/src/Viewer.tsx 0% 0% 0% 0% 1-1053
examples/src/Components/CacheAndStreamingLogs.tsx 0% 0% 0% 0% 1-59
examples/src/Components/RecordMovieComponent.tsx 0% 0% 0% 0% 1-86
src/constants.ts 100% 100% 100% 100%
src/index.ts 100% 100% 100% 100%
src/controller/index.ts 29.02% 61.11% 19.64% 29.02% 83-84, 92-109, 126-173, 176-180, 183-188, 191-192, 195-198, 206-207, 213-227, 231-232, 244-248, 251-254, 257-281, 284-289, 292-293, 296-299, 313-314, 318-319, 334-336, 339-344, 348-349, 354-355, 367-374, 378-380, 383-391, 394-407, 410-470, 473-474, 477-478, 481-491, 494-497, 500-508, 511-519, 522-552, 559-565, 575-576, 579-580, 583-584, 587-588, 591-592, 595-596, 599-600, 603-604, 607-608, 611-612, 615-616, 619-620
src/simularium/VisData.ts 56.63% 66.66% 52% 56.63% 28-42, 60-61, 64-65, 85, 92-93, 100-104, 107-110, 117-120, 138-141, 161, 170, 172-174, 180-186, 195-201, 211, 213-215, 219-221, 224-226, 233-249, 259, 270-276
src/simularium/VisDataCache.ts 76.54% 75.8% 92.3% 76.54% 52-53, 58-69, 73-80, 114, 125-126, 137-139, 148-149, 173-174, 182-186, 214-216, 225-226, 248-249, 251-253, 258-263
src/simularium/index.ts 100% 100% 100% 100%
src/simularium/types.ts 100% 100% 100% 100%
src/test/DummyRemoteSimulator.ts 72.51% 100% 57.14% 72.51% 92-93, 105-108, 111-112, 117-119, 130-148, 161-170
src/viewport/index.tsx 28.33% 100% 0% 28.33% 118-119, 122-182, 185-249, 252-300, 303-313, 316-405, 538-546, 549-557, 562-588, 591-595, 598-603, 606-610, 613-628, 631-635, 638-682, 685-712, 715-719, 722-726, 729-751
Generated in workflow #539 for commit 068ab48 by the Vitest Coverage Report Action

@@ -70,7 +72,7 @@ interface ViewerState {
agentColors: number[] | string[];
showPaths: boolean;
timeStep: number;
totalDuration: number;
totalSteps: number;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First example of a move away from time values towards frame values, see comments in write up!

Comment on lines +823 to +832
min={0}
step={1}
value={this.state.currentFrame}
max={this.state.totalSteps}
onChange={this.handleScrubFrame}
/>
<label htmlFor="slider">
{this.state.currentTime} / {this.state.totalDuration}
{this.state.currentFrame * this.state.timeStep +
this.state.firstFrameTime}
/ {this.state.totalSteps * this.state.timeStep}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The slider just uses the frame numbers as it's values and derives times for display values.

@interim17 interim17 changed the title Feature/prefetching prefetching Jan 30, 2025
@interim17 interim17 marked this pull request as ready for review January 30, 2025 21:59
@interim17 interim17 requested a review from a team as a code owner January 30, 2025 21:59
@interim17 interim17 requested review from ShrimpCryptid and tyler-foster and removed request for a team January 30, 2025 21:59
Copy link
Contributor

@ShrimpCryptid ShrimpCryptid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments and suggestions!

examples/src/Components/CacheAndStreamingLogs.tsx Outdated Show resolved Hide resolved
examples/src/Components/CacheAndStreamingLogs.tsx Outdated Show resolved Hide resolved
examples/src/Viewer.tsx Show resolved Hide resolved
examples/src/Viewer.tsx Outdated Show resolved Hide resolved
examples/src/Viewer.tsx Outdated Show resolved Hide resolved
src/controller/index.ts Outdated Show resolved Hide resolved
@@ -343,6 +412,7 @@ export default class SimulariumController {
// calls simulator.abort()
this.stop();

// this.abortRemoteSimulation();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove?

src/simularium/VisData.ts Outdated Show resolved Hide resolved
src/simularium/VisData.ts Outdated Show resolved Hide resolved
src/simularium/VisData.ts Outdated Show resolved Hide resolved
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.

2 participants