Skip to content

script: Only register one image callback per CSS image in use.#36612

Merged
jdm merged 1 commit intoservo:mainfrom
jdm:n-squared-callbacks
Apr 19, 2025
Merged

script: Only register one image callback per CSS image in use.#36612
jdm merged 1 commit intoservo:mainfrom
jdm:n-squared-callbacks

Conversation

@jdm
Copy link
Copy Markdown
Member

@jdm jdm commented Apr 19, 2025

When layout encounters a CSS image, the script thread is responsible for fetching the image from the image cache. When the image is not yet available, the script thread creates image cache listeners to perform actions in response to future updates from the image cache.

In the current implementation, a cache listener would iterate over all nodes using a particular image and mark them as dirty. However, we mistakenly added one cache listener per node, leading to n^2 runtime while performing lots of redundant work. For cases like #36480 with over 1000 elements using the same image, this led to a completely unresponsive script thread.

Testing: Manual testing on the provided testcase, and a new WPT test that times out without this PR's changes.
Fixes: #36480

@jdm jdm requested a review from gterzian as a code owner April 19, 2025 05:39
@jdm jdm enabled auto-merge April 19, 2025 05:49
@jdm jdm added this pull request to the merge queue Apr 19, 2025
Merged via the queue into servo:main with commit 3ab5b8c Apr 19, 2025
21 checks passed
@jdm jdm deleted the n-squared-callbacks branch April 19, 2025 07:14
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.

Layout-initiated image loads perform n^2 callbacks

2 participants