You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
iOS: measure/optimize EPUB repaginate(for:) cost on large books #336
ReaderView.repaginate(for:) (iOS EPUB reader, landed in #331/PR #333) re-lays-out every chapter of the book synchronously on the main thread, via TextPaginator.paginate (TextKit NSLayoutManager/NSTextContainer), every time it's triggered: device rotation, Split View/Slide Over resize on iPad, or a font size / line spacing / font design change in Reading Settings.
For a typical-length book this is presumably fine, but there's currently zero test coverage or measurement against a realistically large book (a long novel, an omnibus, a technical reference with many long chapters). Worst case this is a visible main-thread hang/jank on rotation or when adjusting the font-size slider (which can fire repaginate on every intermediate value if not debounced — worth checking).
Suggested scope
Measure real-world repagination cost against a large EPUB (e.g. time repaginate(for:) for a several-hundred-page book on a real device or Simulator).
If it's actually slow: consider debouncing font/line-spacing slider changes before repaginating, paginating chapters lazily/incrementally (e.g. only the current + adjacent chapters up front, rest on demand) instead of the whole book up front, or moving the TextKit layout work off the main thread.
Add a test or benchmark that would catch a regression here.
Origin
Flagged as a non-blocking observation in principal review of PR #333 (real EPUB pagination): #333 (comment)
Not a correctness bug — no CONFIRMED issue, just an unverified performance risk worth checking on-device.
Triage: reproduced the concern by reading ReaderView.repaginate(for:) and TextPaginator.paginate. Confirmed: repaginate(for:) does call chapters.map { TextPaginator.paginate(...) } — every chapter, synchronously, on the main thread — and the font-size/line-spacing sliders in ReaderSettingsSheet use step: 0.1 (not continuous), so a full drag can still fire repagination up to ~7 times in a row, each doing a whole-book layout.
Scoping this: I can't run a real device/Simulator measurement from this environment directly, but this repo's iOS CI (ios-app-build.yml) does run LibraVaultTests on a macOS runner with a real Simulator, so I'm going to add a regression/benchmark test against a realistically large synthetic book (~30 chapters, ~900k characters total) that exercises the actual TextPaginator.paginate path, open the PR, and read the real timing back from that CI run before deciding whether an optimization (debounce / lazy pagination / background layout) is actually warranted, rather than guessing blind. Proceeding.
Automated pipeline health check: Not one of the 5 known failure patterns — flagging a stale in-progress state caused by its linked PR going away, not crashing.
This issue's linked PR, #339 (Closes #336, off-main-thread TextPaginator fix), was just closed unmerged (2026-08-21T04:42:14Z) as superseded: PR #369 (merged 2026-08-20T19:41:09Z, after #339 was opened) replaced the entire pagination mechanism ReaderView uses — it now paginates via BlockPaginator instead of TextPaginator, synchronously on the main thread. TextPaginator is dead code from ReaderView's perspective as of dev, so #339's diff no longer applies (hence its merge conflict) and its whole approach targets a code path that doesn't run anymore.
So #336 is stuck on status:in-progress with no active PR and no crash to retry — the original perf concern (main-thread repagination cost on large books) is still real, but needs to be re-measured and re-scoped against the current BlockPaginator path rather than resuming #339's approach. That's a fresh triage/scoping call, not something in this routine's authorized self-heal set (capacity-cap retry, confirmed-infra retry, stale-branch rebase, pattern-5 near-miss requeue, pattern-4 retry-once).
Recommend a human re-apply status:ready-for-dev (or status:triage) to get a fresh dev-agent pass scoped against BlockPaginator.
PR #339 (this issue's fix) was closed as architecturally obsolete — dev replaced TextPaginator with BlockPaginator (#369) after #339's branch was cut, and ReaderView.repaginate(for:) now runs BlockPaginator.paginate synchronously on the main thread with no off-thread/detached path. #336's underlying perf concern is still real and unaddressed against the current code — re-applying status:ready-for-dev for a fresh dev-agent attempt scoped to BlockPaginator.paginate, not the old TextPaginator path #339 optimized.
Re-scoped and implemented against the current `BlockPaginator` path (per the last comment) in #411: ported forward the actual fix from the closed/obsoleted PR #339 (which had already measured a real ~4.3s main-thread stall for a ~900k-character, 30-chapter book on CI's macOS Simulator runner, back when `ReaderView` still used `TextPaginator`) — moved `repaginate(for:)`'s `BlockPaginator.paginate` loop onto a detached background task with a generation-counter guard, plus a large-book regression-guard test and an off-main-thread-safety test against `BlockPaginator` directly.
I have no Simulator/device in this environment to re-measure `BlockPaginator`'s specific cost (it lays out one TextKit graph per block rather than one per chapter, a different cost shape than what #339 measured), so the new regression test's threshold is a deliberately generous judgment call pending a real CI run — called out explicitly in the PR description for QA/review to revisit if the actual number comes back much lower.
Activity
github-actions commentedon Aug 20, 2026
Triage: reproduced the concern by reading
ReaderView.repaginate(for:)andTextPaginator.paginate. Confirmed:repaginate(for:)does callchapters.map { TextPaginator.paginate(...) }— every chapter, synchronously, on the main thread — and the font-size/line-spacing sliders inReaderSettingsSheetusestep: 0.1(not continuous), so a full drag can still fire repagination up to ~7 times in a row, each doing a whole-book layout.Scoping this: I can't run a real device/Simulator measurement from this environment directly, but this repo's iOS CI (
ios-app-build.yml) does runLibraVaultTestson a macOS runner with a real Simulator, so I'm going to add a regression/benchmark test against a realistically large synthetic book (~30 chapters, ~900k characters total) that exercises the actualTextPaginator.paginatepath, open the PR, and read the real timing back from that CI run before deciding whether an optimization (debounce / lazy pagination / background layout) is actually warranted, rather than guessing blind. Proceeding.fix(ios): run EPUB repaginate() off the main thread (issue #336)
libravault-xyz commentedon Aug 21, 2026
Automated pipeline health check: Not one of the 5 known failure patterns — flagging a stale in-progress state caused by its linked PR going away, not crashing.
This issue's linked PR, #339 (
Closes #336, off-main-threadTextPaginatorfix), was just closed unmerged (2026-08-21T04:42:14Z) as superseded: PR #369 (merged 2026-08-20T19:41:09Z, after #339 was opened) replaced the entire pagination mechanismReaderViewuses — it now paginates viaBlockPaginatorinstead ofTextPaginator, synchronously on the main thread.TextPaginatoris dead code fromReaderView's perspective as ofdev, so #339's diff no longer applies (hence its merge conflict) and its whole approach targets a code path that doesn't run anymore.So #336 is stuck on
status:in-progresswith no active PR and no crash to retry — the original perf concern (main-thread repagination cost on large books) is still real, but needs to be re-measured and re-scoped against the currentBlockPaginatorpath rather than resuming #339's approach. That's a fresh triage/scoping call, not something in this routine's authorized self-heal set (capacity-cap retry, confirmed-infra retry, stale-branch rebase, pattern-5 near-miss requeue, pattern-4 retry-once).Recommend a human re-apply
status:ready-for-dev(orstatus:triage) to get a fresh dev-agent pass scoped againstBlockPaginator.Generated by Claude Code
libravault-xyz commentedon Aug 22, 2026
PR #339 (this issue's fix) was closed as architecturally obsolete —
devreplacedTextPaginatorwithBlockPaginator(#369) after #339's branch was cut, andReaderView.repaginate(for:)now runsBlockPaginator.paginatesynchronously on the main thread with no off-thread/detached path. #336's underlying perf concern is still real and unaddressed against the current code — re-applyingstatus:ready-for-devfor a fresh dev-agent attempt scoped toBlockPaginator.paginate, not the oldTextPaginatorpath #339 optimized.github-actions commentedon Aug 22, 2026
Re-scoped and implemented against the current `BlockPaginator` path (per the last comment) in #411: ported forward the actual fix from the closed/obsoleted PR #339 (which had already measured a real ~4.3s main-thread stall for a ~900k-character, 30-chapter book on CI's macOS Simulator runner, back when `ReaderView` still used `TextPaginator`) — moved `repaginate(for:)`'s `BlockPaginator.paginate` loop onto a detached background task with a generation-counter guard, plus a large-book regression-guard test and an off-main-thread-safety test against `BlockPaginator` directly.
I have no Simulator/device in this environment to re-measure `BlockPaginator`'s specific cost (it lays out one TextKit graph per block rather than one per chapter, a different cost shape than what #339 measured), so the new regression test's threshold is a deliberately generous judgment call pending a real CI run — called out explicitly in the PR description for QA/review to revisit if the actual number comes back much lower.
PR: #411 (draft, marking ready once CI passes).