Skip to content

perf: make screenshots ~10x faster and target resolution non-blocking (#88) - #139

Merged
TMHSDigital merged 1 commit into
mainfrom
perf/async-target-resolution-88
Oct 24, 2026
Merged

TMHSDigital merged 1 commit into
mainfrom
perf/async-target-resolution-88

Conversation

@TMHSDigital

Copy link
Copy Markdown
Owner

Closes #88.

Measured (through the built server, 2-monitor Windows host)

before after
1st screenshot monitor:0 2705 ms 774 ms
2nd / 3rd 2643 / 2510 ms 263 / 233 ms
list_sessions sent mid-screenshot 399 ms 1 ms

What was actually slow

Profiling each step: PowerShell getMonitors ≈ 400 ms, but the ffmpeg grab ≈ 2.1 s. buildScreenshotArgs used -framerate 1, and gdigrab paces at the input rate, so ffmpeg waits about two frame intervals before writing one frame. Measured best-of-3: 1 fps 2061 ms, 5 fps 467 ms, 30 fps 213 ms. The 30 fps still is pixel-identical (same size, same mean luma). -probesize/-analyzeduration don't help. Now SCREENSHOT_GRAB_FPS = 30.

Non-blocking resolution (what the issue asked for)

  • getMonitors() / getRawWindows() / resolveWindowBounds() / resolveCaptureTarget() are async, via a shared runPowerShell() on execFile (was spawnSync).
  • Monitor layout is cached for 5 s (MONITOR_CACHE_MS); concurrent callers share one in-flight query; a failure is not cached. Window positions are never cached, since windows move.

I did not do the "persistent PowerShell helper / prebuilt exe" idea from the issue. With the cache and the framerate fix, a repeat screenshot is now dominated by ffmpeg itself (~0.2 s), so it didn't seem worth a native helper yet.

Tests

  • monitorCache.test.ts (execFile mocked, runs on any OS): reuse within the window, re-query after, shared concurrent query, failure not cached, async execFile used.
  • Full suite 226 pass; live capture harness 10/10 on Windows.

Version 0.14.2.

🤖 Generated with Claude Code

…#88)

Stills grabbed at -framerate 1 made gdigrab wait ~2 s for one frame; they
now grab at 30 fps (pixel-identical, ~0.2 s). Monitor and window queries
run PowerShell through async execFile instead of spawnSync, so the event
loop keeps serving other requests, and the monitor layout is cached for
5 s with shared in-flight queries and no caching of failures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@TMHSDigital
TMHSDigital merged commit c98b4e0 into main Oct 24, 2026
8 checks passed
@TMHSDigital
TMHSDigital deleted the perf/async-target-resolution-88 branch October 24, 2026 20:36
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.

Capture target resolution blocks the event loop for about 1.5 s per call (synchronous PowerShell Add-Type)

1 participant