Skip to content

perf(runtime): compile raw-text closing tags once in WebFetch - #5097

Open
E2ern1ty wants to merge 1 commit into
apache:mainfrom
E2ern1ty:perf/web-fetch-raw-text-regex
Open

perf(runtime): compile raw-text closing tags once in WebFetch#5097
E2ern1ty wants to merge 1 commit into
apache:mainfrom
E2ern1ty:perf/web-fetch-raw-text-regex

Conversation

@E2ern1ty

@E2ern1ty E2ern1ty commented Sep 9, 2026

Copy link
Copy Markdown

Summary

The HTML 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 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 lastIndex immediately before every exec, 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 — clean
  • npm --workspace @maka/runtime run test:dist — 3350 pass / 0 fail, including the new test
  • npx biome check on both changed files — clean

AI use

Select exactly one:

  • No generative tool made a substantive contribution
  • Generative tooling made a substantive contribution

Tool(s) and scope: ZCode authored the change, the new test, and this description.

Checklist

  • Tests cover the change and fail without it
  • Lint, format, typecheck and the affected suites pass locally

Does this PR entail a change in behavior?

  • Yes — described under Summary above
  • No

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
@github-actions github-actions Bot added the effort/S Under 100 readable lines label Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/S Under 100 readable lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant