Update histogram#29
Conversation
WalkthroughThis PR introduces a thread-safe image decoding helper to support background histogram computation without blocking the main thread. It refactors the histogram pipeline to safely fetch decoded images on-demand via the prefetcher, updates the histogram worker signature to support fallback decoding, and adds test data. Documentation describing ICC color profile handling is removed and ignored. Changes
Sequence Diagram(s)sequenceDiagram
participant MT as Main Thread
participant HC as Histogram<br/>Controller
participant HW as Histogram<br/>Worker
participant PF as Prefetcher
participant Cache as Image Cache
MT->>HC: Trigger histogram update
rect rgb(200, 220, 255)
Note over HC: Check if preview data available
alt Preview data available
HC->>HW: _compute_histogram_worker<br/>(decoded provided)
else Preview data unavailable
HC->>HC: Compute target_index
HC->>HW: _compute_histogram_worker<br/>(controller, target_index)
end
end
HW->>Cache: Check cache hit
alt Cache miss
HW->>HC: _get_decoded_image_safe(target_index)
HC->>PF: Delegate decode with priority
PF-->>HC: Return decoded (or None)
HC-->>HW: DecodedImage
else Cache hit
Cache-->>HW: DecodedImage
end
rect rgb(220, 240, 220)
Note over HW: Compute histogram
HW->>HW: Safe fallback if data unavailable
end
HW-->>MT: Histogram result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.gitignoredocs/COLOR_PROFILE_FIX.mdfaststack/app.pyfaststack/tests/dummy_images/faststack.json
💤 Files with no reviewable changes (1)
- docs/COLOR_PROFILE_FIX.md
🧰 Additional context used
🧬 Code graph analysis (1)
faststack/app.py (3)
faststack/models.py (1)
DecodedImage(37-46)faststack/imaging/cache.py (1)
build_cache_key(81-87)faststack/imaging/prefetch.py (1)
submit_task(261-301)
🪛 Ruff (0.14.10)
faststack/app.py
596-596: Do not catch blind exception: Exception
(BLE001)
🔇 Additional comments (4)
.gitignore (1)
31-31: LGTM! Documentation exclusion is appropriate.The addition aligns with the removal of
docs/COLOR_PROFILE_FIX.mdand follows the existing pattern for documentation files.faststack/tests/dummy_images/faststack.json (1)
1-18: LGTM! Test fixture is well-structured.The JSON structure provides a clean baseline for testing with a minimal entry and empty stacks, which is appropriate for test data.
faststack/app.py (2)
701-720: Design choice: Histogram worker can now block on image decode.The updated
_kick_histogram_workerpasses the controller andtarget_indexto enable the histogram worker to fetch and decode images when preview data isn't available (Lines 704-706, 720). This means the histogram worker thread may block waiting for image decode (via_get_decoded_image_safe→prefetcher.submit_task→future.result(timeout=5.0)).Trade-off: This provides a robust fallback for histogram computation when the editor preview isn't ready, but could delay histogram updates by up to 5 seconds on slow decodes. The histogram throttling (50ms timer, line 207) helps mitigate UX impact.
This is a reasonable design choice for this use case where histogram accuracy is prioritized over instant updates.
727-734: Fallback decode path provides robustness for histogram computation.The updated worker signature allows fetching decoded data on-demand via
controller._get_decoded_image_safe(target_index)when preview data isn't available (Lines 732-733). This ensures histograms can be computed even when the editor preview hasn't been rendered yet.The implementation correctly checks for both missing
decodeddata and a validtarget_indexbefore attempting the fetch (Line 732).
Summary by CodeRabbit
Release Notes
Bug Fixes
Chores
✏️ Tip: You can customize this high-level summary in your review settings.