Skip to content

Extraction: Walk the DOM once for hidden elements and scoring - #520

Open
kepano wants to merge 4 commits into
pr/4-content-patterns-footnotesfrom
pr/5-hidden-maincontent-scoring
Open

kepano wants to merge 4 commits into
pr/4-content-patterns-footnotesfrom
pr/5-hidden-maincontent-scoring

Conversation

@kepano

@kepano kepano commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Stacked on #519.

Extraction is 11% faster on linkedom and 15% faster on JSDOM, on top of #519.

removeHiddenElements ran querySelector('math, [data-mathml], .katex-mathml') on every element before checking whether it was hidden. findMainContent ran FOOTNOTE_INLINE_REFERENCES and FOOTNOTE_LIST_SELECTORS for every candidate and scored duplicates again. scoreAndRemove called closest and querySelector for every block.

src/removals/hidden.ts walks the tree, checks hiddenness first, and looks for math only in hidden elements. src/defuddle.ts collects footnote ancestors once and caches candidate scores. src/removals/scoring.ts scores blocks in one walk and shares text, link and heading counts between its content check and its score.

Medians on top of #519: linkedom 1,168 → 1,038 ms, JSDOM 3,959 → 3,349 ms, both outside the spread. Alone on 0.19.11, all three were within the noise. It adds 0.8 KB gzipped to both bundles, and the core budget goes from 99 to 100 KB. +368 / −247 lines.

With all five PRs, extraction goes from 2,012 to 981 ms on linkedom and from 6,760 to 3,322 ms on JSDOM, 51% faster on both, for 5.4 KB gzipped.

Output is byte-identical to #519 for all 250 fixtures, at each fixture's own URL and at https://example.com/page, with no options, separateMarkdown and markdown, under linkedom and JSDOM (1,500 runs each). tsc --noEmit, lint:unused, lint:innerhtml, npm run size and 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant