Skip to content

fix(epub): read a repeated spine part once - #109

Merged
tomsideguide merged 2 commits into
mainfrom
fix/epub-spine-dedupe
Aug 19, 2026
Merged

fix(epub): read a repeated spine part once#109
tomsideguide merged 2 commits into
mainfrom
fix/epub-spine-dedupe

Conversation

@tomsideguide

@tomsideguide tomsideguide commented Aug 19, 2026

Copy link
Copy Markdown
Member

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 itemref re-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.

  • Resolves each itemref to a path and de-duplicates entries that resolve to the same part (including differently spelled hrefs), preserving first occurrence order.
  • Error handling: tracks total spine entries and converted chapters; returns an error only if none convert; warns on unresolvable or unusable chapters, and now includes the resolve error detail in the warning.
  • Adds a test asserting 64 repeated 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.
  • Closes (Optimization?) A 35 KB file is taking ~30s because each itemref re-parsing its part #43.

Written for commit 903e009. Summary will update on new commits.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 1 file

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread src/formats/epub/mod.rs Outdated
@tomsideguide
tomsideguide merged commit 3a64809 into main Aug 19, 2026
5 checks passed
@tomsideguide
tomsideguide deleted the fix/epub-spine-dedupe branch August 19, 2026 17:29
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.

(Optimization?) A 35 KB file is taking ~30s because each itemref re-parsing its part

1 participant