railwaycat / homebrew-emacsmacport

Emacs mac port formulae for the Homebrew package manager
BSD 2-Clause "Simplified" License
1.67k stars 125 forks source link

Many "Emacs Web Content" processes created and never killed #380

Open brendan-m-murphy opened 1 month ago

brendan-m-murphy commented 1 month ago

Activity monitor shows many "Emacs Web Content" processes: image

I'm not sure how many there are, but well over 100. It's hard to find these using ps and I'm not sure how Activity Monitor decides to label them as "Emacs Web Content". The parent process is listed as launchd, they tend to use less than a second of cpu time.

Their "open files and ports" look like:

/System/Volumes/Preboot/Cryptexes/OS/System/Library/Frameworks/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.WebContent.xpc /System/Volumes/Preboot/Cryptexes/OS/System/Library/Frameworks/WebKit.framework/Versions/A/XPCServices/com.apple.WebKit.WebContent.xpc/Contents/MacOS/com.apple.WebKit.WebContent /System/Library/CoreServices/SystemVersion.bundle/en_GB.lproj/SystemVersion.strings /private/var/db/timezone/tz/2024a.1.0/icutz/icutz44l.dat /System/Volumes/Preboot/Cryptexes/OS/System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Resources/en.lproj/Localizable.strings /System/Volumes/Preboot/Cryptexes/OS/System/Library/Frameworks/WebKit.framework/Versions/A/Frameworks/WebCore.framework/Versions/A/Resources/en.lproj/Localizable.stringsdict /System/Library/CoreServices/SystemAppearance.bundle/Contents/Resources/SystemAppearance.car /System/Library/CoreServices/SystemAppearance.bundle/Contents/Resources/FauxVibrantLight.car /Library/Preferences/Logging/.plist-cache.wIUS3Pas /usr/share/icu/icudt74l.dat /System/Library/CoreServices/SystemAppearance.bundle/Contents/Resources/Aqua.car /System/Library/CoreServices/SystemAppearance.bundle/Contents/Resources/VibrantLight.car /System/Library/Fonts/Times.ttc /System/Library/Fonts/Monaco.ttf /private/var/folders/wt/4vh3gw2x4jlgcjsphz5wqgmh0000gp/0/com.apple.LaunchServices.dv/SystemDataOnly-com.apple.LaunchServices-5028-v2.csstore /dev/null /dev/null /dev/null ->0x784796543e355992

I'm not sure what this means, other than maybe it is trying to access fonts.

I'm essentially only using org-mode, magit, shell, and python lsp. I'm not sure what is responsible for creating these processes.

Eventually, emacs hangs for several seconds when doing basic text editing, and I have to close it, then manually close all of these processes (or try to kill them by filtering ps results by PID and CPU time).

I'm happy to investigate more, but I don't really know where to start.

sleetdrop commented 1 month ago

I encountered this when open and close svg file multiple times. Describes in this issue https://github.com/railwaycat/homebrew-emacsmacport/issues/366

'Emacs Web Content' is a process's localizedName, I wrote a tool to kill all of them with the help of chatgpt in swift. I put it in this gist. https://gist.github.com/sleetdrop/e770dc5caf4fa9897f348899d86e06ad

Compile it in xcode, and pass "Emacs Web Content" as parameter to kill all of them.

It maybe related code here https://bitbucket.org/mituharu/emacs-mac/src/65c6c96f27afa446df6f9d8eff63f9cc012cc738/src/macappkit.m#lines-14049:14071 and here https://bitbucket.org/mituharu/emacs-mac/src/65c6c96f27afa446df6f9d8eff63f9cc012cc738/src/macappkit.m#lines-14242:14256

Which are responsible for reusing and releasing of webkit instance for viewing SVG, but I am not familiar with macOS development, I have not found why, anyone familiar with emacs and macOS(objc) can dig more into this issue.

brendan-m-murphy commented 1 month ago

Thanks for the script! I saw the svg issue. I'm not explicitly creating svg's, but maybe something in doom emacs is.