dev@bfd:~/dev-diary$ git show 2026-01
commit 2026-01-15-performance-optimization
Author: MJ
Date: Jan 15, 2026

2026-01-15 - Optimizing Flutter Windows Screenshot Performance

Timeline

  • 10:00 (Context) Analyzed snap_dual repo; identified PowerShell script execution as the primary latency bottleneck (~1.5s).
  • 10:15 (Action) Replaced Process.run based capture with native package:win32 GDI calls.
  • 10:30 (Action) Refactored CaptureService to offload image processing to background Isolates.
  • 10:45 (Observation) Capture latency dropped to <50ms; UI freezes eliminated.

ctx:

  • 10:00 The initial implementation relied on spawning a PowerShell process to capture the screen. The overhead of spinning up the .NET runtime for every screenshot made “instant” capture impossible.
  • 10:05 Identified that image decoding and encoding were occurring on the main UI thread, causing the application to hang visibly during the crop/save phase.

act:

  • 10:15 Integrated package:win32 and dart:ffi. Implemented BitBlt in NativeScreenshotService to copy screen pixels directly into a Dart Uint8List, bypassing disk I/O entirely.
  • 10:25 Modified CropOverlay to accept in-memory image data (Uint8List) instead of file paths, removing the need for intermediate temporary files.
  • 10:35 Wrapped the heavy image library operations (decode, crop, encode) in compute() functions to move them to a background Isolate.

obs:

  • 10:40 Direct GDI capture is orders of magnitude faster than scripting. The “snap” is now effectively instant.
  • 10:45 The “UI Janky” feeling during saving is gone. Using Isolates for image processing allows the loading/success animations to play smoothly while the CPU crunches pixels in the background.

open:

  • 11:00 The current GDI implementation grabs the Virtual Screen bounds. Need to verify behavior on mixed-DPI multi-monitor setups to ensure coordinate mapping remains accurate.
  • 11:00 Consider adding a global low-level keyboard hook (Win32 API) to trigger captures even when the app doesn’t have focus.