Skip to content

fix: cache platform detection results to avoid per-frame system_profiler#149

Merged
inureyes merged 1 commit into
mainfrom
fix/cache-platform-detection
Apr 8, 2026
Merged

fix: cache platform detection results to avoid per-frame system_profiler#149
inureyes merged 1 commit into
mainfrom
fix/cache-platform-detection

Conversation

@inureyes

@inureyes inureyes commented Apr 8, 2026

Copy link
Copy Markdown
Member

Summary

Platform detection functions (has_nvidia, has_gaudi, has_tenstorrent, etc.) in src/device/platform_detection.rs were re-evaluated on every view refresh cycle. On macOS this meant system_profiler SPPCIDataType — a probe that takes hundreds of milliseconds and spawns a fresh process — was running once per frame in local view mode.

Root Cause

In src/view/data_collection/local_collector.rs:565, update_notifications is called from every data collection cycle and evaluates has_nvidia() first in a short-circuit chain:

if has_nvidia()
    && let Some(nvml_message) = get_nvml_status_message()
    && !state.nvml_notification_shown

Because has_nvidia() is the first term, the nvml_notification_shown guard never short-circuits the probe. On macOS the function shells out to system_profiler SPPCIDataType on every call.

Fix

Wrap each platform detection function in a process-global OnceLock, so the underlying probe runs at most once per process:

  • has_nvidia, has_amd, has_furiosa, has_tenstorrent, has_rebellions, has_google_tpu, has_gaudi
  • is_jetson, is_apple_silicon

Hardware presence does not change at runtime, so caching is semantically correct. All call sites in reader_factory, local_collector, main, and client automatically benefit without modification.

Also collapses nested if blocks flagged by clippy::collapsible_if in macOS-specific device readers (cpu_macos.rs, macos_native/*.rs, apple_silicon_native.rs).

Test plan

  • cargo build succeeds
  • cargo clippy clean
  • cargo test passes (5 + 17 + 19 tests)
  • Manual verification on macOS that system_profiler is no longer spawned on every view refresh cycle

Platform detection functions (has_nvidia, has_gaudi, etc.) were re-evaluated
on every view refresh from update_notifications, executing system_profiler
SPPCIDataType once per frame on macOS. The probe takes hundreds of ms and
spawns processes repeatedly even though hardware presence never changes at
runtime.

Wrap each detection function in a process-global OnceLock so the underlying
probe runs at most once per process. Also collapse nested ifs flagged by
clippy in macOS device readers.
@inureyes inureyes added type:bug Something isn't working mode:view View mode related device:apple-silicon Apple Silicon related priority:high High priority issue labels Apr 8, 2026
@inureyes inureyes merged commit 615d5e5 into main Apr 8, 2026
2 checks passed
@inureyes inureyes deleted the fix/cache-platform-detection branch April 8, 2026 12:05
@inureyes inureyes self-assigned this Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

device:apple-silicon Apple Silicon related mode:view View mode related priority:high High priority issue type:bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant