对于mac26 electron应用卡顿问题

222 阅读2分钟

截至2025年10月20日,苹果Mac电脑的最新系统版本为‌macOS Tahoe 26.0.1‌。该版本于10月18日发布,主要针对新款M5设备进行优化,修复了无线连接稳定性、多任务调度等问题,并包含安全补丁。 ‌

版本信息

  • macOS Tahoe 26.0.1‌:适用于2025年发布的M5系列Mac设备(如MacBook Pro、Mac Studio等),包含无线连接优化、FontParser漏洞修补等改进。 ‌1
  • 其他可用版本:macOS Sequoia 15.6.1(2025年8月更新)、macOS Sonoma 14.7.8(2025年8月更新)等。

github.com/electron/el…

Electron-based apps cause a huge system-wide lag on macOS 26

基于 Electron 的应用在 macOS 26 上导致系统级严重卡顿

解决方案: github.com/electron/el…

可以看到已经修复了

image.png

image.png

image.png

这是当前要在新版本上合并的,那么对于没有升级到最新代码的版本怎么解决呢?

github.com/ghostty-org…

这里有一句话

macos: disable NSAutoFillHeuristicController on macOS 26
macos: 在 macOS 26 上禁用 NSAutoFillHeuristicController

Fixes #8616

macOS 26 (as of RC1) has some pathological performance bug where the
terminal becomes unusably slow after some period of time. We aren't 100%
sure what triggers the slowdown, but it is app-wide (new tabs or windows
don't resolve it) and Instruments traces point directly to
NSAutoFillHeuristicController. Specifically, to the `debounceTextUpdate`
selector.

This is all not documented as far as I can find and also not open
source, so I have no idea what's going on.

The best I can tell is that the NSAutoFillHeuristicController has
something to do with enabling heuristic-based autofill such as SMS auth
codes in text input fields. I don't know what is causing it to go
haywire.

SMS autofill is not desirable in a terminal app, nor is any of the other
automatic autofill in macOS I know of (contact info, passwords, etc.).
So, we can just disable it.

This default isn't documented but I found it via a strings dump of the
AppKit binary blob and comparing it to the disassembly to see how it is
used. In my limited testing, this seems to work around the problem.

我们在应用层


// 修复 macOS 26 上的 NSAutoFillHeuristicController 性能问题

// 参考: https://github.com/microsoft/vscode/issues/8616

if (process.platform === 'darwin') {

try {

// 禁用 NSAutoFillHeuristicController 来避免 macOS 26 上的性能问题

app.commandLine.appendSwitch('disable-features', 'AutofillAssistant')

// 额外的 macOS 特定优化

app.commandLine.appendSwitch('disable-background-timer-throttling')

app.commandLine.appendSwitch('disable-renderer-backgrounding')

log.info('已禁用 NSAutoFillHeuristicController 以修复 macOS 26 性能问题')

} catch (error) {

log.error('禁用 NSAutoFillHeuristicController 时出错:', error)

}

}
打包配置
# 禁用 NSAutoFillHeuristicController 以解决 macOS 26 性能问题

NSAutoFillHeuristicControllerEnabled: false


# 为您的应用专门设置
defaults write com.youid.app NSAutoFillHeuristicControllerEnabled -bool false

# 验证设置是否成功
defaults read com.youid.app NSAutoFillHeuristicControllerEnabled

总结

现在您有了三层保护来禁用 NSAutoFillHeuristicController :

  1. 应用级别 :通过 defaults 命令直接设置(立即生效)
  2. 构建级别 :在 electron-builder.yml 中配置(永久生效)
  3. 运行时级别 :在 index.ts 中通过命令行参数禁用(已完成) 这种多层次的配置确保了 NSAutoFillHeuristicController 在各种情况下都被正确禁用,从而解决 macOS 26 RC1 的性能问题。

建议操作顺序 :

  1. 先执行 defaults 命令(立即生效)
  2. 重新构建应用以应用 Info.plist 更改
  3. 测试应用性能是否有改善