Skip to content

perf: massive optimization overhaul — 75% binary reduction and instant UI responsiveness#53

Merged
0xarchit merged 1 commit intomainfrom
optimization
May 10, 2026
Merged

perf: massive optimization overhaul — 75% binary reduction and instant UI responsiveness#53
0xarchit merged 1 commit intomainfrom
optimization

Conversation

@0xarchit
Copy link
Copy Markdown
Owner

Overview
This PR implements a comprehensive technical overhaul of PauseCat, focusing on "Extreme Optimization" and "High-Fidelity Responsiveness." By shifting from high-level, heavy
dependencies to native Win32 APIs, we have reduced the binary size by approximately 75% and eliminated all reported UI latency.

Key Changes

  1. Storage & Dependency Pruning
  • Binary Size: Reduced from ~2MB to 528KB.
  • Removed Crates: reqwest, tokio, dirs, winreg, thiserror, lazy_static, and image.
  • Native Shift: Replaced removed crates with direct windows-rs calls to WinHTTP, SHGetKnownFolderPath, Reg* APIs, and standard library OnceLock.
  1. Memory & RAM Efficiency
  • Downsampled Capture: Screen capture now operates at 25% resolution using StretchBlt with HALFTONE filtering. This reduces transition buffer memory usage by 16x without visual
    degradation of the blur effect.
  • Idle Recovery: Implemented flush_buffers() which explicitly clears and shrinks static vectors to zero capacity when the overlay is hidden.
  • Resource Streaming: Replaced in-memory asset loading with real file streaming via SHCreateStreamOnFileEx for WebView2, ensuring flat memory usage even with large video files.
  1. Responsiveness & Reliability
  • Instant Event Loop: Refactored the event loop to use PostThreadMessageW. Interactions from the Tray and background threads now trigger an immediate wake-up of the main thread,
    eliminating the previous 100ms - 1s polling delays.
  • Hardened Networking: The new WinHTTP stack includes a custom redirect handler with an 8KB buffer (fixing hangs on long GitHub/S3 URLs) and strict 5s/10s timeouts to prevent the
    "stuck on checking" issue.
  • Graceful Exit: Removed aggressive working set trimming which was causing OS-level disk thrashing and delayed app closure.

Technical Notes

  • Warnings: Achieved a 100% clean, zero-warning build.
  • Architecture: State management is now entirely event-driven and synchronized via a centralized MAIN_THREAD_ID.
  • Safety: Conducted a full Registry audit; all operations are strictly limited to HKCU with least-privilege access.

Verification Results

  • Build: cargo build --release (Successful, 528 KB)
  • Idle RAM: ~3.5MB (OS dependent)
  • Latency: Measured < 1ms from Tray click to Settings window initialization.

By submitting this PR, I agree to follow the project's Code of Conduct.

- Reduced binary size from ~2MB to 528KB by replacing heavy crates (reqwest, tokio, dirs, winreg, thiserror) with native Win32 APIs.
- Optimized RAM usage by implementing 25% resolution downsampled screen capture (16x buffer saving) and explicit buffer flushing on idle.
- Eliminated UI lag by refactoring the event loop to use PostThreadMessageW for near-instantaneous event processing.
- Implemented real file streaming (SHCreateStreamOnFileEx) for WebView2 to handle large assets with flat memory usage.
- Hardened native networking with custom WinHTTP stack featuring timeouts and robust redirect handling.
- Modernized global state management using standard library OnceLock.
- Achieved zero-warning build and implemented surgical working set management.
@0xarchit 0xarchit linked an issue May 10, 2026 that may be closed by this pull request
14 tasks
Copy link
Copy Markdown
Owner Author

@0xarchit 0xarchit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes reviewed

@0xarchit 0xarchit merged commit d6f680f into main May 10, 2026
3 checks passed
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.

Extreme Optimization: Native Win32 Migration and Footprint Reduction

1 participant