perf: move sampling to a background thread and cache static driver facts#35
Merged
Conversation
Signed-off-by: chang-ning <spiderpower02@gmail.com>
Signed-off-by: chang-ning <spiderpower02@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR moves hardware/stat sampling off the UI thread into a dedicated background sampler and caches static GPU-driver facts, reducing cold-start latency and preventing slow driver calls from freezing rendering/input.
Changes:
- Add a background
Samplerthread that collects subsystem snapshots into a single-slot mailbox for the UI. - Refactor TUI state updates to consume sampler snapshots with per-subsystem baselines and staleness/death reporting.
- Cache “static while driver is loaded” GPU metadata (NVML + XGMI topology) to avoid repeated expensive queries.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/sampler.rs | New background sampling thread + mailbox (Snapshot) API. |
| src/tui/app.rs | Replace synchronous polling with apply_snapshot, add per-subsystem baselines, and add tests. |
| src/main.rs | Wire the sampler into the TUI main loop and propagate refresh interval changes. |
| src/tui/ui.rs | Add “initializing/failed” placeholders and status-bar warnings for stalled/dead sampler. |
| src/nvlink.rs | Cache NVML init for process lifetime and cache per-link static metadata. |
| src/xgmi.rs | Cache XGMI peer adjacency matrix and reuse it during per-GPU snapshot construction. |
| src/trace.rs | Timestamp trace samples using sampler-side timestamps. |
| src/stat.rs | Document intentional non-caching of RDMA port link rate due to retraining/down-port behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: chang-ning <spiderpower02@gmail.com>
Signed-off-by: chang-ning <spiderpower02@gmail.com>
Signed-off-by: chang-ning <spiderpower02@gmail.com>
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.
Purpose
Cold start blocked on two full sampling passes plus NVML/amdsmi driver init before the first frame,
Nvml::init()/nvmlShutdownran every tick, and any slow driver call froze rendering and input.cargo fmt --checkpassescargo clippy -- -D warningspassescargo testpasses