fix: cache platform detection results to avoid per-frame system_profiler#149
Merged
Conversation
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.
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.
Summary
Platform detection functions (
has_nvidia,has_gaudi,has_tenstorrent, etc.) insrc/device/platform_detection.rswere re-evaluated on every view refresh cycle. On macOS this meantsystem_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_notificationsis called from every data collection cycle and evaluateshas_nvidia()first in a short-circuit chain:Because
has_nvidia()is the first term, thenvml_notification_shownguard never short-circuits the probe. On macOS the function shells out tosystem_profiler SPPCIDataTypeon 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_gaudiis_jetson,is_apple_siliconHardware presence does not change at runtime, so caching is semantically correct. All call sites in
reader_factory,local_collector,main, andclientautomatically benefit without modification.Also collapses nested
ifblocks flagged byclippy::collapsible_ifin macOS-specific device readers (cpu_macos.rs,macos_native/*.rs,apple_silicon_native.rs).Test plan
cargo buildsucceedscargo clippycleancargo testpasses (5 + 17 + 19 tests)system_profileris no longer spawned on every view refresh cycle