Repository navigation
Conversation
Every end tag rescans the pending end tag handlers of all still-open elements, so documents with many open elements take quadratic time. With an end tag handler on every element, "<div><b></b>".repeat(100_000) (1.2 MB) takes 1.34s; with this change, 0.05s. Real pages hit this through unclosed <tr>, <td> or <dd>. On a corpus of slow real-world pages the scan is 46% of extraction CPU; removing it halves the total and makes the worst pages 66-86% faster. Typical pages are unchanged. Find the handlers to run from the back instead, using the existing active count, so open elements are never visited. Reset the count before handlers run, so it stays correct if one fails or panics. Dispatch order and output are unchanged (identical on 104k pages).
remusao
requested review from
a team,
Noah-Kennedy,
jasnell and
orium
as code owners
October 8, 2026 10:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Every end tag rescans the pending end tag handlers of all still-open elements, so documents with many open elements take quadratic time. With an end tag handler on every element,
"<div><b></b>".repeat(100_000)(1.2 MB) takes 1.34s; with this change, 0.05s.Real pages hit this through unclosed
<tr>,<td>or<dd>. On a corpus of slow real-world pages the scan is 46% of extraction CPU; removing it halves the total and makes the worst pages 66-86% faster. Typical pages are unchanged.Find the handlers to run from the back instead, using the existing active count, so open elements are never visited. Reset the count before handlers run, so it stays correct if one fails or panics. Dispatch order and output are unchanged (identical on 104k pages).