Fix high main thread CPU usage caused by save dialog on macOS 26

Commit: a91f3332 | 2025-09-16 05:51:24+00:00

← Back to List

Fix high main thread CPU usage caused by save dialog on macOS 26

Moderate
Commit Hash: a91f333207ec3099fef26e0f22743943cdafa07c
Commit Time: 2025-09-16 05:51:24+00:00
Impact Level: Moderate
Generated By: webview2-upstream-sentry
Upstream Review: View Upstream Review πŸ”—

πŸ“‹ Summary

This commit fixes the issue of frequent main thread calculations caused by using the firstBaselineAnchor property of NSPopUpButton for auto layout on macOS 26. Starting from macOS 26, the firstBaselineAnchor property of NSPopUpButton triggers frequent calculations on the main thread of the main process, resulting in higher CPU usage. Referring to Safari’s implementation, switching the constraint to the centerYAnchor property can reduce CPU overhead. Visually, since the font size of NSPopUpButton and labels is the same on macOS 26, center alignment shows almost no noticeable difference compared to previous firstBaseline alignment. The change only affects the CreateAccessoryView function in the select_file_dialog_bridge.mm file.

🎯 Impact Analysis

This change has a positive performance impact on WebView2Mac. WebView2Mac inherits the remote_cocoa::mojom::Application interface through HostingApplicationBridge and directly uses remote_cocoa::SelectFileDialogBridge to display file dialogs. When a user triggers a file selection operation (such as uploading a file) in WebView2Mac, the SelectFileDialogBridge::Show method is called, which internally uses the CreateAccessoryView function to create the accessory view for the dialog. On macOS 26 systems, this optimization will significantly reduce CPU usage when displaying file dialogs, improving user experience, especially during frequent file selection operations. This improvement does not affect functionality; it is purely a performance optimization and ensures compatibility across different macOS versions through version checks.

Impacted Classes:

remote_cocoa::SelectFileDialogBridge remote_cocoa::mojom::Application