Repository navigation
perf: make screenshots ~10x faster and target resolution non-blocking (#88) - #139
Merged
Merged
Conversation
…#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]>
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.
Closes #88.
Measured (through the built server, 2-monitor Windows host)
screenshot monitor:0list_sessionssent mid-screenshotWhat was actually slow
Profiling each step: PowerShell
getMonitors≈ 400 ms, but the ffmpeg grab ≈ 2.1 s.buildScreenshotArgsused-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/-analyzedurationdon't help. NowSCREENSHOT_GRAB_FPS = 30.Non-blocking resolution (what the issue asked for)
getMonitors()/getRawWindows()/resolveWindowBounds()/resolveCaptureTarget()are async, via a sharedrunPowerShell()onexecFile(wasspawnSync).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.Version 0.14.2.
🤖 Generated with Claude Code