fix(2785): performance cores showing 75% instead of 100% when fully utilized #2814
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.
Problem
On systems like M4 Pro 12/16, when performance cores are fully utilized, the Details section incorrectly shows Performance Cores: 75% instead of 100%, even though the bar graph displays correctly.
This occurs when CPU IDs from IORegistry don't align with sequential logical CPU indices from
host_processor_info. The buggy code used CPU IDs directly as array indices (usagePerCore[Int(c.id)]), causing out-of-bounds lookups that returned 0 for cores with non-sequential IDs (e.g., IDs 20, 21 when the array only has indices 0-11).Issue: #2785
Solution
Replaced ID-based matching with positional matching to correctly map cores to usage data:
usagePerCore[Int(c.id)](uses CPU ID as index)usagePerCore[index](uses position in cores array)This ensures that
cores[i]always maps tousagePerCore[i], regardless of what CPU IDs are stored in the core objects.Changes
Core Fix
calculatePerformanceCoresUsage(cores:usagePerCore:)calculateEfficiencyCoresUsage(cores:usagePerCore:)enumerated().compactMapcores.count == usagePerCore.count) before calculationsLoadReaderto use the new functionsTesting
Testing
All 13 tests pass, including:
Impact