From a0f893ace6ac8cbcf9681774d44053fa88a97143 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:27:25 +0000 Subject: [PATCH] perf: optimize critical rendering and data processing paths - Refactor `AmbientBackground` to use `ResizeObserver` instead of polling layout in animation loop. - Implement async chunking for `ExploreDataService` to prevent main thread blocking during heavy calculations. - Throttle `UrlHealthController` video probes to a maximum of 3 concurrent requests to prevent resource exhaustion. - Document optimization tasks in `OPTIMIZATION_TASKS.md`. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- OPTIMIZATION_TASKS.md | 50 ++++++++++++ js/services/exploreDataService.js | 34 +++++--- js/ui/ambientBackground.js | 35 ++++++-- js/ui/urlHealthController.js | 128 +++++++++++++++++------------- 4 files changed, 179 insertions(+), 68 deletions(-) create mode 100644 OPTIMIZATION_TASKS.md diff --git a/OPTIMIZATION_TASKS.md b/OPTIMIZATION_TASKS.md new file mode 100644 index 00000000..b73b78a4 --- /dev/null +++ b/OPTIMIZATION_TASKS.md @@ -0,0 +1,50 @@ +# Optimization Task Stubs + +The following tasks were identified and implemented to resolve high CPU/GPU usage and potential crashes on the website. + +## Completed Tasks + +### 1. Optimize Ambient Background Animation +**Problem:** The `AmbientBackground` controller was calling `resizeCanvas` inside the `requestAnimationFrame` loop. This function accessed `getBoundingClientRect()`, causing synchronous layout thrashing (forced reflow) on every frame, leading to high CPU/GPU usage. +**Fix:** +- Refactor `js/ui/ambientBackground.js` to use `ResizeObserver`. +- Only update canvas dimensions when the element actually resizes. +- Remove layout reads from the animation loop. + +### 2. Async Chunking for Explore Data Service +**Problem:** `ExploreDataService` performed heavy synchronous iterations over large datasets (Watch History and Video Tags) on the main thread. This could cause the UI to freeze (long tasks) during initialization or updates. +**Fix:** +- Refactor `buildWatchHistoryTagCounts` and `buildTagIdf` in `js/services/exploreDataService.js`. +- Implement processing in chunks (e.g., 500 items). +- Yield to the main thread using `setTimeout` between chunks to allow user interaction and frame rendering. + +### 3. Throttle URL Health Video Probes +**Problem:** The `UrlHealthController` spawned a `