Skip to content

Various fixes applied. See PR for more details.#1

Open
ChrisMenning wants to merge 3 commits into
masterfrom
performance
Open

Various fixes applied. See PR for more details.#1
ChrisMenning wants to merge 3 commits into
masterfrom
performance

Conversation

@ChrisMenning
Copy link
Copy Markdown
Owner

@ChrisMenning ChrisMenning commented Mar 12, 2026

Fixes applied

  1. paginate_html — per-word Image allocation (epub_reader_controller.py)
    A fresh Image.new("1", (1, 1)) + ImageDraw.Draw(...) was created for every word during word-wrap measurement. A single _measure_draw object is now created once per call and reused — eliminating thousands of object allocations per chapter.

  2. _extract_pages — entire book paginated at startup (epub_reader_controller.py)
    All chapters were paginated upfront before showing anything. Now only the first chapter is loaded; next_page / prev_page already had chapter-transition logic that was dead code — it's now live. load_chapter() caches chapters to avoid re-paginating on revisit.

  3. display_Partial — sends full 48 000-byte frame over SPI (epd7in5_V2.py)
    The buffer was allocated as int(self.width * self.height / 8) (full frame) and transmitted in full over SPI even for a tiny radio-button region. It now allocates and sends only Width × Height bytes for the actual region.

  4. init_part() called on every encoder tick (epaper_display_output.py, reader_modal_view.py)
    init_part() performs a hardware reset + full SPI init sequence. It was called on every rotary encoder step. Both call sites now guard with if _display_mode != "partial" so the hardware is only initialised once when entering partial mode.

  5. _display_mode tracking + ensure_full_mode() (epaper_display_output.py, tomereader.py)
    EPaperDisplay now tracks display mode ("full" / "partial"). A new ensure_full_mode() method reinitialises hardware only when actually switching back from partial mode, replacing the two display.init_display() calls after modal close that triggered a full e-paper clear+reinit (and visible blank-flash) unconditionally.

  6. CBZReaderView — 4-gray mode on a 1-bit framebuffer (cbz_reader_view.py)
    The CBZ reader called update_display(mode="4gray"), which is significantly slower than 1-bit mode. The display framebuffer is Image.new("1", ...), so pasting onto it already converts to binary — the 4-gray encode loop runs for no quality benefit. Changed to mode="1".

  7. show_page() — re-parses chapter HTML on every page turn (epub_reader_controller.py)
    show_page() called BeautifulSoup(item.get_content(), ...) and searched headings on every single page turn just to populate the footer title. Results are now stored in _chapter_title_cache and parsed at most once per chapter.

  8. cbz_reader_view.py — display_page now composes a fresh "L"-mode canvas locally, pastes the grayscale page onto it, draws the footer directly on that canvas, then passes it to the new display_gray_direct() method. The 1-bit shared framebuffer is never touched.

  9. epaper_display_output.py — new display_gray_direct(img_L) method rotates the L-mode image and sends it straight to display_4Gray / getbuffer_4Gray, preserving all gray levels end-to-end.

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.

1 participant