Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 3, 2025

Problem

The HTMLDocument::simulateScrollWithOffset method was dispatching scroll events on every scroll operation without any rate limiting, causing performance issues during rapid scrolling scenarios. This was inconsistent with the Element::simulateScrollWithOffset method, which already had throttling implemented.

Solution

Added 16ms scroll event throttling (~60fps) to HTMLDocument::simulateScrollWithOffset to match the existing implementation in Element::simulateScrollWithOffset. This ensures consistent performance optimization across the entire DOM hierarchy.

Changes Made

src/client/dom/document.hpp:

  • Added #include <chrono> for time-based throttling
  • Added private shouldThrottleScrollEvent() method declaration
  • Added throttling fields:
    • last_scroll_event_time_ to track the last scroll event time
    • scroll_throttle_duration_{16} for 60fps throttling (16ms intervals)

src/client/dom/document.cpp:

  • Implemented shouldThrottleScrollEvent() method using the same logic as Element
  • Modified simulateScrollWithOffset() to use throttling before dispatching scroll events
  • Only dispatches scroll events when the throttle duration has elapsed

docs/internals/DOM_SCROLLING_PERFORMANCE.md:

  • Updated documentation to reflect that both Element and HTMLDocument now have throttling
  • Added implementation details for document-level scrolling optimization

Performance Impact

  • Before: Unlimited scroll event frequency during rapid scrolling
  • After: Maximum 60fps scroll event rate (16ms throttling)
  • Benefit: Significant reduction in CPU overhead and improved scroll performance consistency

The implementation is identical to the existing Element throttling mechanism, ensuring maintainability and consistent behavior across the codebase.

Testing

  • ✅ C++ formatting check passes
  • ✅ Code compiles without errors
  • ✅ Implementation matches existing Element throttling pattern
  • ✅ Documentation updated to reflect changes

This change maintains full backward compatibility while providing the performance optimization requested in the issue.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • registry.npmmirror.com
    • Triggering command: npm ci (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: yorkie <1935767+yorkie@users.noreply.github.com>
Copilot AI changed the title [WIP] 在 HTMLDocument::simulateScrollWithOffset 也实现滚动的截流来优化性能 Implement scroll throttling in HTMLDocument::simulateScrollWithOffset for performance optimization Sep 3, 2025
Copilot AI requested a review from yorkie September 3, 2025 17:11
@yorkie yorkie marked this pull request as ready for review September 3, 2025 17:54
@yorkie yorkie merged commit 1668735 into main Sep 3, 2025
2 checks passed
@yorkie yorkie deleted the copilot/fix-8be10eb8-8e05-4233-ba2d-d58c89c1166c branch September 3, 2025 17:56
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