Skip to content

perf: move sampling to a background thread and cache static driver facts#35

Merged
crazyguitar merged 5 commits into
mainfrom
perf/enhancement
Jul 11, 2026
Merged

perf: move sampling to a background thread and cache static driver facts#35
crazyguitar merged 5 commits into
mainfrom
perf/enhancement

Conversation

@crazyguitar

Copy link
Copy Markdown
Member

Purpose

Cold start blocked on two full sampling passes plus NVML/amdsmi driver init before the first frame, Nvml::init()/nvmlShutdown ran every tick, and any slow driver call froze rendering and input.

  • cargo fmt --check passes
  • cargo clippy -- -D warnings passes
  • cargo test passes
  • Tested on RDMA-capable hardware (or explained why not in the Test Plan)
  • Docs/README updated if behavior or flags changed

Signed-off-by: chang-ning <spiderpower02@gmail.com>
Signed-off-by: chang-ning <spiderpower02@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Sampler thread 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.

Comment thread src/sampler.rs
Signed-off-by: chang-ning <spiderpower02@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.

Comment thread src/nvlink.rs
Comment thread src/sampler.rs
Comment thread src/sampler.rs
Comment thread src/trace.rs Outdated
Signed-off-by: chang-ning <spiderpower02@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/sampler.rs
Signed-off-by: chang-ning <spiderpower02@gmail.com>
@crazyguitar
crazyguitar merged commit 5778b19 into main Jul 11, 2026
4 checks passed
@crazyguitar
crazyguitar deleted the perf/enhancement branch July 11, 2026 18:08
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.

2 participants