Skip to content

perf: reduce startup cost and add robustness improvements#862

Open
SemmerSky wants to merge 1 commit into
dynobo:mainfrom
SemmerSky:pr/perf-small-fixes
Open

perf: reduce startup cost and add robustness improvements#862
SemmerSky wants to merge 1 commit into
dynobo:mainfrom
SemmerSky:pr/perf-small-fixes

Conversation

@SemmerSky
Copy link
Copy Markdown

@SemmerSky SemmerSky commented May 20, 2026

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.cache on get_available_handlers() (screenshot, clipboard, positioning)
Replaces the manual global _available_handlers_cache pattern. 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 zxingcpp
Moved 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 TimeoutError message tells the user what happened and why.

dbus_portal timeout 10s → 5s
The 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

  • All existing tests pass
  • Tested on Fedora 44, KDE Plasma 6.3, Wayland, pip install (uv pip install -e ".[dev]")

- 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>
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