fix(epub): read a repeated spine part once - #109
Merged
Conversation
There was a problem hiding this comment.
All reported issues were addressed across 1 file
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
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.
The spine was never deduplicated, so n itemrefs naming one href parsed it n times. In the reported file that href is the package document itself, whose size grows with n, so a 35 KB book took 27 seconds and a 69 KB one did not finish.
Itemrefs now resolve to a part path once and dedupe on it, which also catches two hrefs spelling the same part differently.
This closes a second case the issue does not cover: pointed at a real chapter instead of the package document, the same file rendered that chapter n times, emitting one anchor id n times and turning 19 KB of input into 3.2 MB of output. Duplicate anchor ids make intra-book links ambiguous.
n=6400 goes from 27s to 0.01s, n=12800 from not finishing to 0.4s, and the amplified case from 3.2 MB to 1011 bytes.
Closes #43
Summary by cubic
Deduplicates EPUB spine entries by resolved part path so a repeated part is parsed and rendered once. Previously each repeated
itemrefre-parsed and re-rendered the same part (often the package document), duplicating anchors and causing severe slowdowns; now each unique part is processed once in first-occurrence order.itemrefto a path and de-duplicates entries that resolve to the same part (including differently spelled hrefs), preserving first occurrence order.itemrefs yield a single chapter’s text; performance improves from 27s→0.01s at n=6400 and from hang→0.4s at n=12800; amplified output drops from 3.2 MB to 1011 bytes.Written for commit 903e009. Summary will update on new commits.