⚡ Implement lazy loading for PDF content to improve performance #29
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.
This PR implements lazy loading for PDF documents in
ContentRepository. Previously, opening a large PDF would block execution while the application extracted text from every page, split it into paragraphs, and created a large list ofContentElementobjects.The new implementation uses
PdfLazyList, a customAbstractListthat opens the PDF document and extracts text for a specific page only when requested by the UI (e.g., byLazyColumnorHorizontalPager). This reduces the initialization complexity from O(N) (where N is the number of pages) to O(1).Key changes:
ContentRepository.kt: AddedPdfLazyListand updatedloadPdfContentto use it.ContentResult.kt&ChapterContent.kt: Added support for passing pre-calculatedtextCountandimageCountto avoid iterating the lazy list for metadata.ReaderViewModel.kt: Updated to propagate these counts.Note: PDF content is now returned as one text block per page (preserving paragraph breaks via double newlines), which aligns better with page-based navigation and enables the lazy loading strategy.
PR created automatically by Jules for task 141534413232369332 started by @Aatricks