fix: memoize static disk-name resolution so the Dashboard 2s temp poll stops re-querying WMI/SMART#1426
Merged
Conversation
…l stops re-querying WMI/SMART RefreshTemperaturesAsync calls TemperatureService.ReadAllAsync() with includeStorage defaulting to true, so on an elevated session the Dashboard's 2s poll ran, every tick: GetDiskNamesFromWmi() (a Win32_DiskDrive query) AND EnrichStorageNamesAsync -> DiskHealthService.CollectAsync() (MSFT_PhysicalDisk enumeration + per-disk MSFT_StorageReliabilityCounter SMART walk — the heaviest part of a read). All of it just to relabel LHM storage sensors with disk friendly-names, which are static hardware identity. Both resolutions are now memoized once (mirroring the _nvApiInitTried 'resolve static hardware once' pattern): _cachedWmiDiskNames under _sensorLock, and _cachedStorageFriendlyNames behind a SemaphoreSlim gate that makes the first resolution race-safe across the 2s poll, the user Refresh, and the 10s sampler. After the first read the hot poll only calls LHM Update() for live temps. Fixes ultra-audit finding P2 #14. Regression test (integration): EnrichStorageNames_ResolvesOnce_AndCachesFriendlyNames drives the private enricher twice and asserts the cache field is populated once and reference-stable (CollectAsync degrades to empty on a WMI-less CI host but still caches, so the assertion is deterministic).
| await _enrichGate.WaitAsync().ConfigureAwait(false); | ||
| try | ||
| { | ||
| if (_cachedStorageFriendlyNames is null) |
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
Fresh ultra-audit finding (performance, P2), verified against current source.
RefreshTemperaturesAsynccallsTemperatureService.ReadAllAsync()withincludeStoragedefaulting to true. On an elevated session, the Dashboard's 2-second temperature poll (the Dashboard is the app's default/home tab) therefore ran, on every tick:GetDiskNamesFromWmi()— aWin32_DiskDriveWMI query, andEnrichStorageNamesAsync→DiskHealthService.CollectAsync()— anMSFT_PhysicalDiskenumeration plus a per-diskMSFT_StorageReliabilityCounter(SMART) association walk, which the code's own comments call "by far the heaviest part of a read."All of that was spent solely to relabel LibreHardwareMonitor storage sensors with disk friendly-names — static hardware identity that never changes. (The 10s resource sampler was already optimized to skip this with
includeStorage:false; the more frequent Dashboard poll was not.)Fix
Both resolutions are memoized once, mirroring the existing
_nvApiInitTried"resolve static hardware once" pattern:_cachedWmiDiskNames(??=, under the existing_sensorLock)._cachedStorageFriendlyNamesbehind aSemaphoreSlimgate (double-checked) so the first resolution is race-safe when the 2s poll, the user's Refresh, and the 10s sampler overlap.After the first read the hot poll only calls LibreHardwareMonitor's
Update()for live temperatures._enrichGateis disposed inDispose().Regression test (integration)
EnrichStorageNames_ResolvesOnce_AndCachesFriendlyNames— drives the private enricher twice and asserts_cachedStorageFriendlyNamesis populated once and reference-stable across calls (proving it resolves once).DiskHealthService.CollectAsync()degrades to an empty list on a WMI-less CI host but still caches, so the assertion is deterministic.Checks