Skip to content

Bound the lazy CBR page cache and remove stale temp extraction #45

Description

@JoshCLWren

Problem

The lazy CBR loader in archives.py now avoids eager extraction, but it stores every decompressed page permanently:

extracted_cache: dict[str, bytes] = {}

Reading through a large comic can retain the full decompressed size of the archive in process memory. This is an improvement over eager startup extraction, but memory usage can still grow without bound during a long reading session.

The same refactor still creates a tempfile.mkdtemp() directory even though it no longer writes extracted files there. That directory and its shutil.rmtree() cleanup should either be removed or given a clear purpose.

Fix

  • Replace the unbounded dictionary with a bounded cache, preferably using the project’s existing cache conventions or a byte-budgeted LRU.
  • Define and document the cache limit based on decoded/compressed page bytes.
  • Keep concurrent rar.read() calls serialized as required by the backend.
  • Remove the unused CBR temporary directory, or use it only if the selected extraction strategy requires it.
  • Ensure cleanup closes/releases all archive resources and clears cached bytes.

Tests

  • Read more pages than the cache capacity and assert old entries are evicted.
  • Assert the cache never exceeds its configured byte/item budget.
  • Assert repeated reads hit the cache.
  • Assert cleanup releases the archive and cache state.
  • Add a large synthetic-member test without weakening benchmark assertions.

Done criteria

  • CBR memory usage remains bounded while paging through a large archive.
  • Solid RAR reads do not regress into repeated unnecessary decompression.
  • No unused temporary directories remain.
  • Existing CBR ordering, cleanup, and error behavior remain covered.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions