fix(web): viewport reactivity, off-screen thumbhashes being rendered #15435
+183
−52
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.
Description
Changing the viewport results in a lot of repeated work because of the
viewport
andsafeViewport
variables being$state
objects andupdateViewport
separately triggering another update. This was exacerbated by the fact that thumbhashes were processed eagerly without checking if they're intersected, meaning that larger buckets could have hundreds of thousands of thumbhashes processed as a user changes the viewport.This PR makes three primary changes:
updateViewport
.updateViewport
's throttling is changed to debouncing and can be automatically shifted to a "large bucket" mode with more aggressive debouncing settings. The default trigger to enable this mode is to have more than 3000 assets in a single bucket. This effectively means that instead of having the layout react as you're dragging, it will react once you stop moving it.The result is that both initial page load, changing viewport and moving around in the timeline is more responsive than before. There is a caveat in that the initial page load is more likely to display gray boxes initially instead of the thumbhash because of the intersection check. Scrolling displays the thumbhash as normal, though.
This was primarily tested alongside the justified layout changes (will be a separate PR), but I split it out into its own PR.
How Has This Been Tested?
Tested with average bucket sizes of 200, 600, 1000, 2000, 3500 and 30000 and confirmed that it (more or less) held up at those numbers, 30000 still being quite slow but usable.
Edit: in the current iteration of this PR, small date groups (<=100 assets) will continue to have thumbhashes eagerly processed so the thumbhashes appear in the first frame. At this scale, it does not seem to cause major issues besides high RAM usage, although it is less responsive than the original version of this PR. I think getting the best of both worlds would require deeper changes, like having a single larger canvas for the date group that gets updated instead of many small canvases, or possibly using WebGL etc.