Repository navigation
Conversation
JavaScriptCore (Safari, WKWebView) can't JIT-compile a regex that contains a lookbehind, so the ~550-way PARTIAL_SELECTORS alternation ran in its interpreter: removeBySelector took 150-1900 ms per parse in WebKit on long pages, against 3-5 ms in Chrome. Patterns with a lookbehind now get a regex of their own; a string matches the alternation exactly when it matches one of the two parts. Applied to PARTIAL_SELECTORS_REGEX and PARTIAL_SELECTORS_ANCHORED_REGEX (both only call .test). A test checks both agree with the combined regex. Fixes kepano#439 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Fixes #439.
JavaScriptCore (Safari, WKWebView) can't JIT-compile a regex that contains a lookbehind. Three
PARTIAL_SELECTORSpatterns have one, so the whole ~550-wayPARTIAL_SELECTORS_REGEXran in JSC's interpreter. In WebKit,removeBySelectortook 150–1,900 ms per parse on long pages, against 3–5 ms in Chrome.Change
compileAlternation()insrc/constants.tscompiles the patterns without a lookbehind into one regex and those with one into another. It returns{ test }, which is true when either matches. A string matches an alternation exactly when it matches one of its parts, so results don't change.PARTIAL_SELECTORS_REGEXandPARTIAL_SELECTORS_ANCHORED_REGEX. Both are internal and only called with.test()(src/removals/selectors.ts).tests/partial-selectors-regex.test.tschecks that both testers agree with the combined regex: on edge cases for each lookbehind pattern and on every literal token (1,109 cases).Results
WKWebView (Safari 26.2 engine), defuddle full build on a
cloneNode(true)copy, median of 3 runs. Outputcontentis byte-identical before and after on all three pages.removeBySelectorbefore → afterparse()before → afternpm testpasses: all library tests, including the new file. The only failures are thewebsitetest files, which need thewebsite/dependencies installed.npm run lint:unusedandnpm run buildalso pass.🤖 Generated with Claude Code