Install with --with-native-compilation option causes scrolling stutters and produces an error on exit
Closed this issue ยท 7 comments
What you were trying to do
Install emacs-mac with the --with-native-compilation
option on both an Intel and M1 MacBook running macOS 13.4.1.
What happened
$ brew install emacs-mac --with-modules --with-native-compilation --with-emacs-big-sur-icon
Everything appears to install okay. At first doom emacs was giving me errors when I tried to run any doom command like doom sync
. I fixed that by reinstalling gcc and libgccjit though.
brew reinstall gcc libgccjit
Now emacs-mac installs without error, and doom sync
, doom upgrade
, and doom doctor
all work without errors.
So far so good! But here's where I run into two problems.
Problem 1
When scrolling through a file in emacs, there are stutters every 0.5-1.0 seconds. This is when holding the j/k keys to move the cursor up and down the file.
Problem 2
When exiting emacs C-x C-c
, immediately upon exiting, macOS throws up an error report. Sometimes I get 1 report, sometimes I get 2, and sometimes I get 3, all when quitting the application a single time.
-------------------------------------
Translated Report (Full Report Below)
-------------------------------------
Process: Emacs [5536]
Path: /Applications/Emacs.app/Contents/MacOS/Emacs
Identifier: org.gnu.Emacs
Version: 28.2 (1.1)
Code Type: ARM-64 (Native)
Parent Process: Exited process [4959]
User ID: 502
Date/Time: 2023-07-02 01:03:45.3254 -0700
OS Version: macOS 13.4.1 (22F82)
Report Version: 12
Anonymous UUID: 5D1D276B-9C2F-AC00-AA1A-BAB97C9ECC29
Sleep/Wake UUID: F2B232A1-D8A1-489B-BE36-CEE3DB3C8CEA
Time Awake Since Boot: 84000 seconds
Time Since Wake: 4402 seconds
System Integrity Protection: enabled
Crashed Thread: 1 org.gnu.Emacs.lisp-main
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Thread 0:: Dispatch queue: com.apple.main-thread
0 libsystem_kernel.dylib 0x19fdbbe90 semaphore_wait_trap + 8
1 libdispatch.dylib 0x19fc4c99c _dispatch_sema4_wait + 28
2 libdispatch.dylib 0x19fc4d050 _dispatch_semaphore_wait_slow + 132
3 Emacs 0x104ac10a4 mac_gui_loop + 40
4 Emacs 0x104ad9464 main.cold.1 + 16
5 Emacs 0x104ac0e14 main + 616
6 dyld 0x19faa3f28 start + 2236
Thread 1 Crashed:: org.gnu.Emacs.lisp-main
Solution
The only thing that fixes both of the above problems, at least that I've been able to determine, is not using the --with-native-compilation
when building emacs-mac.
$ brew install emacs-mac --with-modules --with-emacs-big-sur-icon
When I build without native-compilation, scrolling works without issue, and I get no errors when exiting the app.
It's worth noting that I was able to get rid of the errors when exiting the app by creating an early-init.el file that contained the following (when I was running emacs with the --with-native-compilation
option):
(setenv "LIBRARY_PATH"
(string-join
'("/opt/homebrew/Cellar/gcc/13.1.0"
"/opt/homebrew/opt/libgccjit/lib/gcc/current"
"opt/homebrew/opt/gcc/lib/gcc/current/gcc/aarch64-apple-darwin22/13")
":"))
Even though this fixed my error when exiting the application, I still ended up with stuttering when scrolling through files.
Output of brew config
$ brew config HOMEBREW_VERSION: 4.0.26 ORIGIN: https://github.com/Homebrew/brew HEAD: eff45ef570f265e226f14ce91da72d7a6e7d516a Last commit: 5 days ago Core tap JSON: 02 Jul 08:10 UTC HOMEBREW_PREFIX: /opt/homebrew HOMEBREW_BAT_THEME: OneHalfLight HOMEBREW_CASK_OPTS: [] HOMEBREW_GITHUB_API_TOKEN: set HOMEBREW_MAKE_JOBS: 10 HOMEBREW_NO_ANALYTICS: set HOMEBREW_NO_INSECURE_REDIRECT: set Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby CPU: 10-core 64-bit arm_firestorm_icestorm Clang: 14.0.3 build 1403 Git: 2.41.0 => /opt/homebrew/bin/git Curl: 7.88.1 => /usr/bin/curl macOS: 13.4.1-arm64 CLT: 14.3.1.0.1.1683849156 Xcode: N/A Rosetta 2: false
Output of brew doctor
$ brew doctor Your system is ready to brew.
While the stuttering's happening, do you have a buffer called *Async-native-compile-log*
? (SPC-b-B
to switch to it) Emacs used significant CPU for me until that buffer's process finished after a few minutes.
While the stuttering's happening, do you have a buffer called
*Async-native-compile-log*
? (SPC-b-B
to switch to it) Emacs used significant CPU for me until that buffer's process finished after a few minutes.
Thank you for the reply. That looks like it solves my first problem! ๐
I wasn't giving emacs enough time, and it was still compiling for about 4-5 minutes the first time I open the app (after install Doom emacs).
Cool! I'm also here from Doom - found your issue while looking through doom doctor
output.
Can confirm I've also got your second issue. Though adding the LIBRARY_PATH
value at the end of ~/.config/emacs/early-init.el
doesn't prevent the crashes on exit for me (adding it earlier tells me that string-join
's definition is void). I've confirmed I have all 3 directories.
Looks like the last path in LIBRARY_PATH
is missing a leading /
.
The crashes only happen for me after opening files (elisp config), not if I exit from the splash screen. They happen whether loading the last session in Doom or opening files directly.
Cool! I'm also here from Doom - found your issue while looking through
doom doctor
output.Can confirm I've also got your second issue. Though adding the
LIBRARY_PATH
value at the end of~/.config/emacs/early-init.el
doesn't prevent the crashes on exit for me (adding it earlier tells me thatstring-join
's definition is void). I've confirmed I have all 3 directories.Looks like the last path in
LIBRARY_PATH
is missing a leading/
.The crashes only happen for me after opening files (elisp config), not if I exit from the splash screen. They happen whether loading the last session in Doom or opening files directly.
Are you on an ARM or Intel Mac? The LIBRARY_PATH
I posted above is for an ARM Mac. Homebrew uses a different base path for Intel machines, so if you're on Intel I think that needs to be changed to /usr/local
.
@kris-anderson you still have a missing slash above:
"opt/homebrew/opt/gcc/lib/gcc/current/gcc/aarch64-apple-darwin22/13")
@kris-anderson you still have a missing slash above:
"opt/homebrew/opt/gcc/lib/gcc/current/gcc/aarch64-apple-darwin22/13")
Thank you for catching that!
Just to update my post, this seems to have been fixed in version 29 of Emacs. I no longer get error reports (my second issue) when exiting Emacs! :)
Are you on an ARM or Intel Mac? The
LIBRARY_PATH
I posted above is for an ARM Mac. Homebrew uses a different base path for Intel machines, so if you're on Intel I think that needs to be changed to/usr/local
.
Sorry for the delayed reply, I'm on an ARM Mac as well. Glad that it's fixed, my error reports are gone too! ๐