perf: reduce startup cost and add robustness improvements#862
Open
SemmerSky wants to merge 1 commit into
Open
Conversation
- Replace manual global cache with @functools.cache on get_available_handlers() in screenshot, clipboard, and positioning (fixes ruff PLW0603) - Lazy-import zxingcpp inside _detect_codes_via_zxing() — only loaded when a barcode/QR capture is actually requested, avoids the import cost on every other startup - Add 30s timeout to Tesseract subprocess with a clear TimeoutError message; without this a hung Tesseract silently freezes NormCap indefinitely - Reduce dbus_portal timeout from 10s to 5s — both GNOME and KDE portals respond in under 2s in 2026; the original comment asked to revisit in 2024 - Remove unreachable else-branch in detector.py (ruff SIM108) Tested on Fedora 44, KDE Plasma 6.3, Wayland, pip install. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What this does
A handful of small, independent improvements I noticed while using NormCap daily on Fedora 44 / KDE Plasma 6.3 / Wayland.
Changes
@functools.cacheonget_available_handlers()(screenshot, clipboard, positioning)Replaces the manual
global _available_handlers_cachepattern. Functionally identical but cleaner and fixes ruff PLW0603. The conftest already calls.cache_clear()between tests so nothing else needs to change.Lazy import of
zxingcppMoved inside
_detect_codes_via_zxing(). The import only happens when a barcode/QR capture is actually requested saves measurable startup time on every other capture. Also removes unreachable dead code in the same function (ruff SIM108).Tesseract subprocess timeout (30s)
Without this, a hung Tesseract silently freezes NormCap indefinitely. The
TimeoutErrormessage tells the user what happened and why.dbus_portaltimeout 10s → 5sThe original comment asked to revisit this in 2024 once portals were expected to always return a response. Both GNOME (gnome-shell ≥41) and KDE portals do so reliably now. 5s still gives ample margin for slow hardware.
Testing
uv pip install -e ".[dev]")