Repository navigation
Conversation
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.
Extraction is 19% faster on linkedom and 23% faster on JSDOM.
removeBySelectorranquerySelectorAll(EXACT_SELECTORS_JOINED), so linkedom's css-select tested every element against 166 selectors, many of them attribute tests like[class*="pagination" i]. Its removal loop also ranFOOTNOTE_LIST_SELECTORSthroughmatches,querySelectorandclosestfor every element it was about to remove.src/utils/selector-matcher.tsreadsEXACT_SELECTORSfromsrc/constants.tswhen it loads. Plain tag, id and class selectors go into Sets. Compound selectors with attribute tests and:not()become JS tests indexed by tag, attribute or class. The three:has()selectors runmatches()only onaudio,videoandheader, and the three with combinators go to onequerySelectorAll. The removal loop collects footnote lists and their ancestors once.I kept the matcher small rather than writing a full selector compiler. It follows two rules that are easy to miss: values of HTML attributes such as
typeandrelmatch case-insensitively, and quirks-mode pages, where browsers and JSDOM match classes case-insensitively, usequerySelectorAll.tests/selector-matcher.test.tscompares the matcher withquerySelectorAllfor seven lists fromsrc/constants.tson every fixture.Medians: linkedom 1,880 → 1,523 ms, JSDOM 6,732 → 5,202 ms, both outside the spread. It adds 1.3 KB gzipped to the core bundle and 1.4 KB to the full one, and the core budget goes from 94 to 96 KB. +228 / −5 lines.
Output is byte-identical to
mainfor all 250 fixtures, at each fixture's own URL and athttps://example.com/page, with no options,separateMarkdownandmarkdown, under linkedom and JSDOM (1,500 runs each).tsc --noEmit,lint:unused,lint:innerhtml,npm run sizeand both Vitest suites pass. Timing alternates fresh processes of each branch over 0.19.11's 248 fixtures, 9 pairs on linkedom and 7 on JSDOM. I haven't run it in a browser, happy-dom or the Cloudflare Worker, and the output check doesn't cover debug mode.