Skip to content

perf(smc): skip absent key probes in long-lived polling - #70

Open
ZongziForu wants to merge 1 commit into
ProducerGuy:mainfrom
ZongziForu:perf/smc-key-inventory
Open

ZongziForu wants to merge 1 commit into
ProducerGuy:mainfrom
ZongziForu:perf/smc-key-inventory

Conversation

@ZongziForu

Copy link
Copy Markdown

Repeated polling currently probes every cross-generation thermal key, including keys absent from the connected Mac. On a MacBookPro17,1, 41 of the 50 temperature keys are absent, so each status() repeatedly pays for unsuccessful readKeyInfo calls.

This adds a connection-local firmware key inventory for the long-lived monitor and daemon. A key is skipped only after the entire inventory has been enumerated successfully. Partial/failed enumeration permits all reads and retries later; ordinary value-read failures never mark a sensor missing. App and daemon wake paths invalidate the inventory on their serialized hardware queues.

The existing performance work in #11 addresses polling cadence, successful key-info caching and observation. This PR targets absent-key probes separately and is based on current main. Default polling intervals, profiles, temperature thresholds and command behavior retain their existing implementation. One-shot CLI callers do not opt into inventory discovery.

Validation

  • swift test: 157 tests passed, including five new inventory tests for different machines, failed/partial enumeration, malformed/duplicate entries and invalidation.
  • swift build -c release: passed.
  • Read-only hardware validation on MacBookPro17,1: the same nine temperature keys were returned with caching disabled/enabled.
  • Three alternating runs using the included benchmark, 200 measured status() reads each after five warm-up reads:
Run Inventory disabled, mean ms Inventory enabled, mean ms
1 13.53 5.51
2 12.96 5.53
3 13.04 5.59

This is about a 58% reduction in warm status() wall time on this machine, not a whole-app CPU claim. The opt-in first read costs about 274–293ms to enumerate the inventory, once per connection or wake. Non-opted-in first reads remained around 12–14ms. Hardware/workload results may differ; other models are covered by inventory tests rather than physical validation.

Tools/benchmark-smc-status.swift includes build/run instructions; compare its default invocation with --inventory. It performs reads only and never controls fans.

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.

1 participant