perf(gliff-server): take blocking work off the session thread #89
All Vouch review confidence checks passed
Residual risk 0.42 = Change Risk (0.52) × (1 − Review Confidence (0.20)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 27% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #89"
general
weight: 0.35
greptile-apps[bot]
Summary
Each session runs on one current-thread tokio runtime, and its
select!loop did the slow work inline. A frame's encode takes 7 to 8.5 ms on the GPU tier at 1080p and 21 to 43 ms on the CPU tier (docs/architecture.md, Measurements), and client input, acks and pings waited behind it. The next capture was requested only after the encode returned. Hyprland IPC calls, which block on a socket read with a 5 s timeout, also ran on the loop.The loop stays the only owner of session state. Three commits move the blocking work out of it:
1. Hyprland IPC on the blocking pool. The loop's
monitors()and mode calls go throughspawn_blocking, so the reader and writer tasks keep running while Hyprland answers.2. Encode on a dedicated thread. The
gliff-encodethread builds and owns the encoder, because the Vulkan Video encoder is notSend. At most one encode is in flight. Frame ids are assigned in order when an encode finishes, and pacing still runs from the dispatch time. A frame whose output changed during its encode is dropped and forces a keyframe. A ladder step or resize finishes the encode in flight before itsStreamConfig, so no frame at an old size follows one.3. Open the GPU during output setup.
VideoTier::openruns onspawn_blockingwhilesetup_outputcreates the output and waits for its mode. Output errors are still reported first, with the same messages.Evidence
Claude Opus 5.5 assisted with the implementation. I reviewed the code myself, as a Rust developer since before AI coding assistants.
After: no message waited over 5 ms on the CPU tier. The GPU tier keeps 57 fps on lan and dsl.
scripts/bench.shin a nested Hyprland 0.56.2 mirroring a 1648x1362 output, 20 s per run, two runs per cell. RTX 3060 with Vulkan Video on the GPU tier, OpenH264 2.6.0 on the CPU tier. The wait is the time from a client message reaching the session's channel to its handling, measured with a temporary debug log that is not part of this PR.| Tier, preset | Wait p99 ms, main | Wait p99 ms, PR | Longest wait ms, main | Longest wait ms, PR | fps, main | fps, PR |
|---|---|---|---|---|---|---|
| CPU, lan | 45.3, 40.4 | 0.0, 0.0 | 92.8, 55.3 | 0.0, 0.0 | 22.6, 21.9 | 30.8, 21.7 |
| CPU, dsl | 40.7, 41.8 | 0.0, 0.0 | 80.7, 80.2 | 0.0, 0.1 | 22.8, 19.0 | 24.2, 20.9 |
| CPU, satellite | 27.4, 23.3 | 0.0, 0.0 | 27.4, 23.3 | 0.0, 0.0 | 0.9, 2.8 | 0.6, 0.4 |
| GPU, lan | 0.0, 0.0 | 0.0, 0.0 | 0.0, 0.0 | 0.0, 0.0 | 57.0, 57.1 | 56.9, 57.1 |
| GPU, dsl | 0.1, 0.1 | 0.0, 0.0 | 6.7, 0.4 | 0.0, 0.0 | 57.2, 57.1 | 57.0, 57.1 |
| GPU, satellite | 0.0, 0.0 | 11.2, 0.0 | 0.0, 0.0 | 11.2, 0.0 | 2.5, 1.3 | 9.8, 1.0 |
Frame ids were strictly increasing in all 24 runs. The CPU tier's frame rate moves with background load (median encode 25 to 38 ms across runs), not with this PR; see Merge Danger. The one wait in the PR's GPU satellite run is the encoder rebuild after a ladder step to 824x680, which blocks the loop on
maintoo.hello_ackon a--headlessGPU session, four interleaved rounds.main: 869, 897, 873 and 877 ms. This PR: 502 ms in every round. Nested headless outputs on this machine never get their mode, so setup waited its full 500 ms and the whole GPU open fit inside it. On a host where the mode applies at once, the saving is only as long as that wait.gliff-server, and the laptop connects to it over ssh. Every check passed:- the GPU tier streams a moving picture
- resizing the client window during motion keeps the picture live, on the GPU tier and on the CPU tier
- a private screen follows the window, and disconnecting removes it and ends the server
- a private screen starts sooner than on
mainscripts/e2e.shon the laptop passed steps 1 to 7: the headless GPU server, the CPU tier matrix, and the CPU fallback after a mirrored resize. It then failed at 7b withE2E FAIL: rotated GPU pipeline. That step only runsgliff-probe pipelineon a rotated output.gliff-probedoes not usegliff-server, and this PR changes only a comment in the crates it does use, somainfails the same way. Steps 7c to 12 did not run.scripts/check.sh: CHECK PASS on each of the three commits (rustfmt, clippy-D warnings, 277 tests on the last). New unit tests: the encoder thread applies encodes and rate changes in order, and a failed rebuild keeps the old encoder.Merge Danger
Door: two-way.
No protocol, config or CLI change. Reverting restores the inline encode.
Blast Radius: video pipeline.
main. Both are rare next to the per-frame wait this removes.update_fps_cmdstill caps it at one frame per measured encode time plus 10 %, so the overlap shows up as lower input latency, not more frames. Relaxing that cap belongs in its own PR.Displayis now opened on one thread and driven from another. ItsSendandSyncsafety comment now says "one thread at a time", which every hand-off (a channel or a join) keeps.mainwith a 100 msshutdown_timeout. Nothing from this PR is still running then: the GPU open is joined even when output setup fails, and dropping the session joins the encoder thread. The two branches merge without conflicts, and the merged tree passes clippy and thegliff-servertests. #80 (audio) adds work to the same loop, so the two may conflict.Follow-ups, out of scope here: relax the CPU tier's fps cap, nested headless outputs that stay 0x0 (they block the headless cases of
bench.shande2e.shon some machines), and the rotated GPU pipeline failure at e2e step 7b.