rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.55k stars 876 forks source link

lldb hangs 1-2s on window example when Ctrl+key / Cmd+key pressed for the first time #3760

Open zhaop opened 5 days ago

zhaop commented 5 days ago

Description

When I run the window example with lldb:

cargo build --example window && lldb -o run target/debug/examples/window

and when I press Ctrl+key or Cmd+key for the first time, lldb hangs for a while and loads a bunch of symbol tables with Apple-sounding names, which causes the example app to hang for 1-2s. Subsequent shortcut presses do not cause this hang.

I've bisected this behavior to 075996b1, which fixes #3231 "feat: macos services menu added". Prior to this commit, reproducing the steps above does not cause a hang.

This also happens when I launch the window example as above, then go to the top left corner of my screen and hover over the "Services >" menu item -- lldb also loads symbol tables for 1-2 seconds, the "Services" menu item hangs, and then after that, the Services submenu appears.

image

This issue came from Bevy issue 14010.

macOS version

ProductName:                macOS
ProductVersion:         14.3.1
BuildVersion:           23D60

Winit version

0.30.0

madsmtm commented 5 days ago

I can reproduce the issue, removing the setServicesMenu call in https://github.com/rust-windowing/winit/blob/82d9bbe5598c8605a752641a477261de01340aed/src/platform_impl/apple/appkit/menu.rs#L85 prevents the hang.

The hang is also present in bog-standard applications created via. Xcode, try creating a new Xcode app, restart Xcode (or kill the lldb-rpc-server process), debug the application, and then close it with CMD + Q. The hang is less noticeable there because:

  1. They spawn a LLDB server, so during normal development flow the symbol table is cached (it's only present the first time debugging after Xcode launches).
  2. Xcode's LLDB seems to do less work at this stage, maybe some custom configuration, maybe changes in their fork, so instead of 1-2 seconds it only takes what feels like half a second.

In any case, I'm not sure what you want Winit to do about it? Maybe you could file an issue with LLDB or Apple instead?