Slow initial app window opening, but only in certain situations?
I use some apps that can accept files a few ways:
- open and then use its own file select dialog
- "open with" from Finder
- "drag & drop" from Finder
Method 1 is fine and the app responds as expected.
Methods 2 & 3 result in the app opening—you can see the app's menu bar and dock icon—but then there is a delay of 4 or 5 seconds before the app window appears.
Apple say:
Engineering has determined that your bug report (39378510) is a duplicate of 19293778 and will be closed.
But why the delay? What is macOS doing? How can I remove the delay?
I've tried:
- reset launch services (no difference)
- new/guest user account (no delay!)
Most interestingly:
- Build new app with unique ID (no delay on first launch; delay on second launch)
- Delete Saved Application State for the app (no delay!) but this regenerates with every run of the app
- Deleting only the file data.data (download that file) in the Saved Application State (no delay!)
Workaround: I can prevent Saved Application State on a per-app basis. See here: https://github.com/sveinbjornt/Platypus/issues/110#issuecomment-377398429
Any ideas appreciated.
- mac OS 10.13.6
- no antivirus
Here are two videos:
xACT.app: https://youtu.be/IzUbQaPzAhA
Platypus.app: https://youtu.be/Omn0pHl7oQw
So it seems that the app is for an as yet unknown reason tied-up opening its com.organisation.AppName.savedState
from ~/Library/Saved Application State/
. I found this out by using FSMonitor whilst launching the app and confirmed it using AppCleaner.
Looking inside the .savedState
file I can see that there's a file restorecount.plist
, present for exactly as long as the delay, which contains an incremented number which on my install of macOS is about 544,000,000 right now. Half a billion windows restored since Mac OS X 10.7 Lion! The ID seems to be system level, as even the Guest user has roughly the same number in its savedState
files.
I'm still interested to know why a new account has faster generation of the
restorecount.plist
file whilst "old" accounts can be a lot slower.
The workaround is to either:
- per-user: enable
System Preferences > General > Close windows when quiting an app
- per-app: in Terminal
defaults write com.organisation.AppName NSQuitAlwaysKeepsWindows -bool false
which stores it in the app's preference file at~/Library/Preferences/
.
Further discussion at this GitHub issue.