Skip to content

Parse each package part once, and bound the total - #44

Open
AbhinavMir wants to merge 1 commit into
firecrawl:mainfrom
AbhinavMir:epub-repeat-parse
Open

Parse each package part once, and bound the total#44
AbhinavMir wants to merge 1 commit into
firecrawl:mainfrom
AbhinavMir:epub-repeat-parse

Conversation

@AbhinavMir

@AbhinavMir AbhinavMir commented Aug 6, 2026

Copy link
Copy Markdown

Packages now cache parsed part trees, so a part referenced many times parses once instead of once per reference, with a running node total bounding the parts too large to cache.

For issue #43.

@AbhinavMir
AbhinavMir marked this pull request as draft August 6, 2026 21:32
@AbhinavMir AbhinavMir changed the title Bound the XML nodes one document may parse in total Parse each package part once, and bound the total Aug 6, 2026
An EPUB whose reading-order entries all point at the package document
parsed that document once per entry, and the document grows with the entry
count: a 35 KB file took 27 seconds and a 69 KB one did not finish. Part
bytes were cached but parsed trees were not, and the per-part node cap
resets on every parse, so nothing bounded the product.

Packages now cache parsed trees and hand callers a shared `Rc`, so a part
referenced many times parses once. The cache holds up to
`max_cached_xml_nodes` (~86 MiB at the measured DOM cost), which covers the
parts documents actually repeat; a part too large for it is served uncached
and still re-parses, so a running node total across the package bounds that
case at `max_document_xml_nodes`.

The 35 KB file now converts in 0.03s and the 69 KB one in 0.02s. Repeated
slide references in a presentation take about half the time they did.
Output is byte-identical across the fixture corpus.
@AbhinavMir
AbhinavMir marked this pull request as ready for review August 6, 2026 22:32
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