caldwell / build-emacs

Build scripts for www.emacsformacosx.com
http://www.emacsformacosx.com/about
GNU General Public License v3.0
364 stars 61 forks source link

Emacs 29 flickering, slow #137

Open jscheid opened 9 months ago

jscheid commented 9 months ago

Hi,

First of all I wanted to say thanks for your work on emacsformacosx.com, it's been my go-to for many years now.

Long version below but tl;dr is:

The long version:

I'm running into troubles with Emacs 29.1-1 as published here (downloaded yesterday via the big button on your main page). I'm pretty sure I've seen the same with earlier versions of Emacs 29 downloaded from here, although I haven't tried reproducing it again with those earlier versions based on what I know now. Emacs 28 is fine.

The issues are a bit hard to describe but they manifest as flickering, sluggishness and occasional "full" hangs that I can't C-g out of, although I haven't had one of those recently and I can't be sure that the hangs aren't fixed by the latest version.

I've found the most reliable way to reproduce the flickering is to run magit-status (with latest vanilla magit from MELPA, no custom config). With the issue present, if the frame is sized so that Magit pops up on the right (rather than the bottom) then the whole frame will go blank while Magit is working, for 1-2 seconds or so. Without it, the part of the frame that isn't occupied by the Magit window stays as-is.

The frame going blank while magit-status runs is jarring, but I want to make it clear that the problem is more widespread. I've just found this to be a good proxy for the overall problem of the screen blanking a lot, which for short blanks manifests in flickering. At least that's my working theory.

None of this is an issue with Emacs 28 (as published here) and based on a quick poll on #emacs nobody else seemed to have heard of anything like it, so my first thought was a misconfiguration on my side. Maybe some old incompatible package lumbering around my .emacs.el, some .elc or .eln file produced by an older Emacs version or something like that. But I've started from scratch, reduced my config to the bare minimum needed to run Magit and I can still reproduce it.

My next thought was that it's a problem with Emacs proper, not with this distribution. I was already settling down for a night of bisecting, but to my surprise, the first build I made (from here) doesn't exhibit the flickering. (Built with just ./configure, i.e. default config arguments, and Xcode 14.0.3... which I should upgrade.)

What's more, this homegrown build is subjectively a lot snappier than the version I downloaded from here. I haven't run any proper benchmarks yet and this is a recent discovery so I couldn't tell you much more, but things like find-file feel instant now when before they were probably taking tens or even (low) hundreds of milliseconds in some situations.

I'm now aware of #107 and perhaps that explains the (lack of) snappiness but it feels to me that something else is going on. After all, native compilation shouldn't have any bearing on the display loop or rendering logic, I think? Besides, my understanding is that native compilation was added in Emacs 28 and that didn't flicker.

Anyway, I'm happy for now and I'll just use my own build. Do let me know if you'd like me to help you get to the bottom of this, though. If so it would be great if you could give me precise instructions on how to build a version locally as close as possible to the one that you're publishing here. I've poked around your build files hoping that I could find a simple configure line somewhere that I could use to try and reproduce, but I think it's more complicated than that.

My test environment: MacBook Pro 16-inch, 2019. 2.4 GHz 8-Core Intel Core i9, Intel UHD Graphics 630 1536 MB, 64 GB 2667 MHz DDR4, macOS 14.1.2 (23B92)

jscheid commented 9 months ago

Just a quick note that I've upgraded to Xcode command line tools 15.0.0 and rebuilt from scratch, and it's still working (snappy and not flickering.)

jscheid commented 9 months ago

I'm trying your build scripts. First, running just ./build-emacs-from-tar emacs-29.1.tar.bz2 release doesn't seem to work: logs (yes the output is garbled like that in my terminal)

Using the --verbose flag raises an error:

/path/to/build-emacs/verbose-shell.rb:16:in `block in system_trace': undefined method `=~' for ["rm", "-rf", "emacs-source"]:Array (NoMethodError)

The following works but prints warnings about "non-encapsulated libs":

./build-emacs-from-tar emacs-29.1.tar.bz2 release -j8 --no-dep

The resulting Emacs works like the ones I'm building manually: snappy and no flickering.

If you could let me know what to do about the error when building deps, I could try that again. If we can get that to work and the build result is also fine, then I guess that would point to the build environment (compiler and such), otherwise a problem with the dependencies.

Or I suppose there could be something with code signing or attestation, or the Rust wrapper, but I'm not immediately sure how to debug that.

jscheid commented 9 months ago

I've got ./combine-and-package Emacs-29.1-14-x86_64.tar.bz2 to work, but maybe the Readme should point out that one needs Ruby 2.x, run cargo build --release and copy the launch executable around.

Anyway, the result works fine. I haven't tried with code signing though.