Parse each package part once, and bound the total - #44
Open
AbhinavMir wants to merge 1 commit into
Open
Conversation
AbhinavMir
marked this pull request as draft
August 6, 2026 21:32
AbhinavMir
force-pushed
the
epub-repeat-parse
branch
from
August 6, 2026 21:32
3d40e4d to
baead09
Compare
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
force-pushed
the
epub-repeat-parse
branch
from
August 6, 2026 21:44
baead09 to
6c958c2
Compare
AbhinavMir
marked this pull request as ready for review
August 6, 2026 22:32
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.
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.