Fix 100% CPU spin on macOS 26 caused by .truncationMode(.middle)#1382
Open
zhouyeyu wants to merge 1 commit intop0deje:masterfrom
Open
Fix 100% CPU spin on macOS 26 caused by .truncationMode(.middle)#1382zhouyeyu wants to merge 1 commit intop0deje:masterfrom
zhouyeyu wants to merge 1 commit intop0deje:masterfrom
Conversation
On macOS 26, NSCoreTypesetter's __NSCoreTypesetterTruncateLine enters an infinite loop when measuring text with .truncationMode(.middle) under an unconstrained height proposal. This occurs during the SlideoutView preview-panel animation, where .fixedSize(horizontal: true) causes SwiftUI to measure the LazyVStack content at ideal (unconstrained) height, triggering text measurement for every history item via that code path. Fix: use .truncationMode(.tail) on macOS 26 to avoid the CoreText bug. The .drawingGroup() workaround for flipped text (p0deje#1113) is preserved and remains safe with .tail truncation. Additional defensive improvements: - HeightReaderModifier: write to @observable keypaths directly instead of via @binding to prevent unintended render dependency registration. - AppDelegate / HistoryItemDecorator: add pending-flag guards to the withObservationTracking re-registration loops to prevent unbounded observation accumulation when multiple mutations fire in one turn.
|
I wasn't able to produce this on macos26.... |
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.
Problem
On macOS 26, Maccy's CPU usage climbs to 100% immediately after launch,
causing the app to become unresponsive. Reproduces on every open of the popup.
Root Cause
NSCoreTypesetter.__NSCoreTypesetterTruncateLine(in UIFoundation) entersan infinite loop when measuring
Textviews with.truncationMode(.middle)under an unconstrained height size proposal.
The trigger path:
SlideoutViewpreview panel starts opening (isAnimating = true).fixedSize(horizontal: true, vertical: false)HistoryItemViewtitle is measured viaNSAttributedString.boundingRectConfirmed via
sampleprofiling: 100% of CPU time in__NSCoreTypesetterTruncateLine_block_invoke.Fix
.truncationMode(.tail)on macOS 26 inListItemTitleView.The existing
.drawingGroup()workaround for flipped text (Flipped labels in macOS Tahoe 26.0 #1113)is preserved and works correctly with tail truncation.
HeightReaderModifier: write to@Observablekeypathsdirectly instead of via a custom
Bindingto avoid unintended renderdependency registration.
AppDelegate/HistoryItemDecorator: guardwithObservationTrackingre-registration callbacks with a pending flagto prevent observation count from growing when multiple mutations fire
in the same turn.