Skip to content

Parser: Fix exponential recursion in two-pass HTML tag matching#840

Merged
marcoroth merged 1 commit into
mainfrom
fix-exponential-recursion
Nov 11, 2025
Merged

Parser: Fix exponential recursion in two-pass HTML tag matching#840
marcoroth merged 1 commit into
mainfrom
fix-exponential-recursion

Conversation

@marcoroth

@marcoroth marcoroth commented Nov 11, 2025

Copy link
Copy Markdown
Owner

This pull request fixes a critical performance regression in the two-pass tag matching algorithm introduced in #795.

Documents that previously parsed in ~75ms were taking ~11 seconds (and in some cases didn't even complete in a reasonable timeframe, see #828).

The match_tags_visitor function was causing double recursion by manually processing array fields through calls to match_tags_in_node_array(), but then returning true which instructed herb_visit_node to also automatically traverse those same children a second time.

This created an exponential explosion where each level of nesting squared the number of visits.

Resolves #828

@github-actions github-actions Bot added the c label Nov 11, 2025
@marcoroth marcoroth merged commit 941bce8 into main Nov 11, 2025
12 checks passed
@marcoroth marcoroth deleted the fix-exponential-recursion branch November 11, 2025 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parser does not terminate within a reasonable time frame

1 participant