Commit Graph
2 Commits
Author SHA1 Message Date
google-labs-jules[bot]andPR0M3TH3AN ea301d1230 Refactor Docs ScrollSpy to use IntersectionObserver and fix dist/src mismatch
Replaces legacy scroll listener with `IntersectionObserver` to eliminate layout thrashing.
- Updates `js/docsView.js` with `rootMargin: "-96px 0px -50% 0px"` and correct scroll-up logic.
- Synchronizes `dist/js/docsView.js` to match the source logic exactly.
- Updates benchmarks to use the same logic for verification.
- Updates lint scripts to exclude benchmarks.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-05 21:21:40 +00:00
google-labs-jules[bot]andPR0M3TH3AN 55a9b937cb Refactor Docs ScrollSpy to use IntersectionObserver
Replaces the scroll event listener and `getBoundingClientRect` polling with `IntersectionObserver` to eliminate layout thrashing and improve scrolling performance.

- Removes `window.onscroll` handler in `docsView.js`.
- Implements `IntersectionObserver` with `rootMargin` to track active headings.
- Retains initial one-time scan for correct state on load.
- Adds benchmark `benchmarks/docs_scroll_spy.html` and `benchmarks/docs_scroll_spy_bench.js`.

Benchmark results:
- Legacy: ~0.065ms/call (200 calls) -> Total ~13ms CPU (sync layout thrashing)
- Optimized: ~0.028ms/call (32 calls) -> Total ~0.9ms CPU
- 14x improvement in CPU time for scroll handler logic.

Co-authored-by: PR0M3TH3AN <[email protected]>
2026-02-05 20:52:52 +00:00