perf(runtime): compile raw-text closing tags once in WebFetch - #5097
Open
E2ern1ty wants to merge 1 commit into
Open
perf(runtime): compile raw-text closing tags once in WebFetch#5097E2ern1ty wants to merge 1 commit into
E2ern1ty wants to merge 1 commit into
Conversation
The nesting scan built a fresh closing-tag RegExp for every script, style, textarea, and title element it met, so a script-heavy page recompiled one of four identical regexes per element. The set is fixed, so the matchers are now derived once at module level. Sharing an instance is safe because lastIndex is assigned immediately before every exec. Also pins the raw-text skip with a test: tag-shaped strings inside script/style content must not count toward the depth limit. Generated-by: ZCode
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.
Summary
The HTML nesting scan built a fresh closing-tag RegExp for every
script,style,textarea, andtitleelement it met, so a script-heavy page recompiled one of four identical regexes per element. The raw-text element set is fixed, so the matchers are now derived once at module level.Sharing a cached RegExp instance is safe here because the scan assigns
lastIndeximmediately before everyexec, so no state leaks between uses.Also adds a test for the raw-text skip path these lines implement, which was previously untested: tag-shaped strings inside script/style content must not count toward the nesting limit (600 fake
<div>s inside a style rule would trip the depth limit if the scanner believed them).Verification
npm --workspace @maka/runtime run typecheck— cleannpm --workspace @maka/runtime run test:dist— 3350 pass / 0 fail, including the new testnpx biome checkon both changed files — cleanAI use
Select exactly one:
Tool(s) and scope: ZCode authored the change, the new test, and this description.
Checklist
Does this PR entail a change in behavior?