Implement scroll throttling in HTMLDocument::simulateScrollWithOffset for performance optimization #289
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.
Problem
The
HTMLDocument::simulateScrollWithOffsetmethod was dispatching scroll events on every scroll operation without any rate limiting, causing performance issues during rapid scrolling scenarios. This was inconsistent with theElement::simulateScrollWithOffsetmethod, which already had throttling implemented.Solution
Added 16ms scroll event throttling (~60fps) to
HTMLDocument::simulateScrollWithOffsetto match the existing implementation inElement::simulateScrollWithOffset. This ensures consistent performance optimization across the entire DOM hierarchy.Changes Made
src/client/dom/document.hpp:
#include <chrono>for time-based throttlingshouldThrottleScrollEvent()method declarationlast_scroll_event_time_to track the last scroll event timescroll_throttle_duration_{16}for 60fps throttling (16ms intervals)src/client/dom/document.cpp:
shouldThrottleScrollEvent()method using the same logic as ElementsimulateScrollWithOffset()to use throttling before dispatching scroll eventsdocs/internals/DOM_SCROLLING_PERFORMANCE.md:
Performance Impact
The implementation is identical to the existing Element throttling mechanism, ensuring maintainability and consistent behavior across the codebase.
Testing
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.comnpm 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.