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

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

← 返回列表

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

Moderate
提交哈希: a91f333207ec3099fef26e0f22743943cdafa07c
提交时间: 2025-09-16 05:51:24+00:00
影响等级: Moderate
生成工具: webview2-upstream-sentry
上游审核链接: 查看上游审核 🔗

📋 摘要

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.

🎯 影响分析

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.

受影响的类:

remote_cocoa::SelectFileDialogBridge remote_cocoa::mojom::Application