Skip to content

Read cached thumbnails independently of generation - #120

Open
k-kostin wants to merge 2 commits into
omacom:mainfrom
k-kostin:codex/thumbnail-cache-lane
Open

k-kostin wants to merge 2 commits into
omacom:mainfrom
k-kostin:codex/thumbnail-cache-lane

Conversation

@k-kostin

Copy link
Copy Markdown
Contributor

Summary

A ready disk-cache PNG currently waits behind running video/PDF/image generation in the provider's one pool. Probe cache entries in a separate two-worker pool; send misses to the existing generation pool, where freshness/cache is checked again. Text pages go straight to their existing generation route.

image request → background cache lookup → fresh PNG: finish
                                    → miss: existing generation queue

No disk access moves to the UI thread, no RAM cache or dependency is added, and generation concurrency remains unchanged. A missing PNG is detected before querying source metadata, avoiding an extra network-source lookup on ordinary cold misses. Cache freshness uses the existing policy.

A response is separate from runnable tasks. Cancellation is checked around the cache stage and before queued generation; destruction drains cache work before generation because cache misses may still enqueue jobs. Every response finishes once. This does not import #117's running-helper cancellation.

Evidence

  • Before: with real generators held in every slot, an existing disk PNG cannot make a QML Image ready before the gate opens. After: it becomes Ready while generators are still held. The test observes persistent QML state, not a racy finished-signal subscription.
  • Eight alternating pairs per direct-provider scenario after warm-up: busy-cache response median 507.9 → 0.57 ms, p95 508.5 → 0.59 ms. This deliberately holds generators for 500 ms; these are response completion times, not displayed-frame latency.
  • Eight 12 MP synthetic JPEGs (baseline/progressive mix), cold thumbnail cache: all responses 210.7 → 209.8 ms median. Idle warm-cache batch: 1.33 → 2.33 ms, reflecting the two-reader bound; first response stays about 0.7 ms. Warm OS page cache throughout.
  • Real Backend/FolderGrid, three pairs each: all eight pictures 227.0 → 227.6 ms, jump to the last of 512 entries 353.3 → 350.2 ms, navigation during generation 43.20 → 43.26 ms. All 18 measured runs complete and drain without failure markers. Offscreen Qt Quick software rendering; physical frame latency was not measured.
  • Release build, diff check and complete local tests: 198 passed, 0 failed, using Qt image plugins matching CI dependencies. Tests cover stale/corrupt/missing cache, removed source, cache recursion and 64 cancelled queued misses.
  • ASan/UBSan with rapid real QML creation/cancellation: candidate 2378 and base 2377 requests all finished and were destroyed while the reader remained alive; no sanitizer errors (leak detection disabled). Immediate engine destruction instead leaves a few responses undestroyed on both versions; that boundary remains recorded and is not fixed here.

Merge Danger

Door: two-way.

Blast Radius: thumbnail admission. Two additional bounded workers can themselves wait on slow cache/source I/O; the existing generation limit is preserved. Pending #67/#117 changes will need the usual rebase and validation before integrating on their final base. This PR targets main independently; #67/#117 are not base dependencies.

@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues were found.

Summary

Cached thumbnails can now finish while thumbnail generation is busy, without changing the generation limit.

  • Cached thumbnails can finish while generation workers are busy.

No actionable issues found. git diff --check passed; tests were not run during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Thumbnail request] --> B{Text page or sharp image?}
    B -->|Yes| G[Existing generation pool]
    B -->|No| C[Two-worker cache pool]
    C --> D{Cancelled or fresh cache hit?}
    D -->|Yes| F[Finish response]
    D -->|No| G
    G --> E[Check cancellation and cache before generation]
    E --> F
Loading

Reviews (2) · Last reviewed commit: "Observe fast cache completion through QM..." · Reviewed by Greptile

@dhh
dhh force-pushed the codex/thumbnail-cache-lane branch from d1b2c8f to 265e923 Compare November 18, 2026 14:39
@dhh

dhh commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Thanks, Kirill. I've rebased this onto main and pushed it to your branch. Two things on main needed fitting in. First, the response's run() is now wrapped in a try/catch so a throwing decoder can't take Folio down (#173). That stays as it was: work() ends in your complete(), and it's marked as told first. Second, the details' new sharp/ requests (#155) have their own cache and id layout, so they now go straight to the generation pool, the same as page/, rather than through cached(), which would misread their ids. thumbnailsCachedImagesDoNotWaitForGenerators still fails when everything goes through one pool and passes with the cache lane. The whole suite passes locally (234 tests).

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

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants