all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Jordan Ellis Coppard <jc+o.emacs@wz.ht>
Cc: emacs-devel@gnu.org
Subject: Re: Emacs graphical frontends / responsiveness
Date: Sun, 20 Oct 2024 22:30:15 +0300	[thread overview]
Message-ID: <861q0ainco.fsf@gnu.org> (raw)
In-Reply-To: <6cadfc93-3fc5-4fcf-b0a6-f54774c36f43@wz.ht> (message from Jordan Ellis Coppard on Mon, 21 Oct 2024 03:46:05 +0900)

> Date: Mon, 21 Oct 2024 03:46:05 +0900
> From: Jordan Ellis Coppard <jc+o.emacs@wz.ht>
> 
> One thing that bothers me without fail is how slow, visually, Emacs is. 

This is partly true (but for good reasons, see below), and partly an
illusion based on wrong expectations (also see below).

> I can often times type faster than the GUI can keep up, with noticeable 
> hitching and delays from when I have typed a character to the point 
> where I see it in a buffer and so forth. This is probably one of the 
> biggest things ruining my experience because no matter how focused I am 
> on the task at hand seeing this behaviour always rips me out of focus. 
> That's also why I feel less productive with Emacs.

This is too general.  Please describe specific situations where this
happens, and please accompany that by the list of optional features
you have turned ON (or try the experiments in "emacs -Q" and see if
the GUI still cannot keep up).  As you might know, some optional
features work by using a post-command-hook, which basically calls some
Lisp when Emacs finishes to process a command.  And since each
keyboard input event is a command in Emacs, the responsiveness is
being slowed by these post-command activities.  Turn on too many of
such features, and you have a slowly-responding Emacs.

> I run a fairly lean Emacs configuration, however even basic behaviour 
> under `emacs -Q` is slow. Take `show-paren-mode` with `show-paren-delay` 
> set to 0; Helix, VS Code, Neovim are able to instantly highlight matched 
> brackets as I move my cursor around. With Emacs there is a noticeable 
> delay (yes even with a delay of 0 and in `emacs -Q`).

show-paren-delay runs off the idle timer, which means it only kicks in
when Emacs detects that it's "idle": it processed the last command and
has no pending input.  Even if you set the delay to zero, the function
which looks for and highlights the matching paren will only be called
when Emacs is idle.  If you type fast enough, it will _never_ be
called.  This is by design: most of such features (at least those of
them that are well-designed) are coded to stay away and not to
interfere with the fast typists among us.  I guess similar features in
Helix, Neovim, etc. are based on different principles.  If you want an
immediate highlighting of the matching parens in Emacs, you will need
a different mode, not show-paren-mode.

> Often times I can type faster than the minibuffer input area can
> handle when filtering completion candidates e.g. `C-h o`.

Once again, tell the details.  Depending on the back-end of the
completion (i.e. the way completion candidates are generated), this
could be slow, indeed.  But the basic completion is quite fast.  I
just typed "C-h o f TAB" and got an immediate popup with the list of
candidates -- and that was in an unoptimized debugging build.  If you
see something else, please tell the details.

> I don't want my editor (or whatever specific title you'd like to apply) 
> to EVER not immediately respond to input unless it's crashed.

See above: some interactive features of Emacs are designed to only
kick in when Emacs is idle, so as not to slow down fast typists.  So
what you say above is either an over-generalization, or maybe you
don't like this design principle, in which case you will need to look
for alternative implementations of the relevant features.

> I don't want my editor running locally only accessing local
> resources to feel like an ssh connection with 200 ms of latency when
> nothing else, nor any other editor I've tried, does.

Again: details, please.  When taken at face values, the above is
simply false, based on 30 years of using Emacs.

> I recently saw in this mailing list Yuan benchmark character insertion 
> into a buffer (with syntax highlighting) at around ~30 ms (if I recall 
> correctly). That's an update rate of 33 times a second, with presumably 
> (for benchmarking's sake) nothing else going on; thus one would assume 
> even lower update rates if you use a few features here and there 
> built-in or otherwise. Emacs struggling to update display in under 16 ms 
> was... shocking to see.

This part is a price we pay for having such a complete and flexible
control on what Emacs does and how it processes and shows stuff.  The
fact that each input event is bound to a command, the fact that these
bindings go through keymaps (which is necessary to allow
customizations of the bindings by major and minor modes), the fact
that many commands have hooks which can be and are used to customize
what the command does and what is done to the editor's state as result
of performing a command, the fact that a Lisp extension can create a
simple data structure which affects how Emacs displays a certain
portion of buffer text (i.e., the display code must consult Lisp data
structures and sometimes run Lisp code) -- these and many other
features don't come for free.  If you want to understand why character
insertion with syntax highlighting is so "slow" in Emacs, you need to
study the processing triggered by inserting a single character, and
realize and appreciate the level of customizability, flexibility, and
control a user-defined Lisp program can have on this processing.  This
is what makes Emacs what it is!  This is why people who like Emacs and
use it for their production tasks will never agree to have an editor
that is less powerful, less flexible, less able to control everything
it does.

> I also recently read this post: 
> https://gist.github.com/ghosty141/c93f21d6cd476417d4a9814eb71dd46e  -- 
> which left me feeling quite sad (if it is accurate) regarding the 
> internals surrounding the GUI and so how apparently needlessly difficult 
> in today's age it would/will be to improve (over how it currently is). I 
> understand the historical legacy.

That blog wants to make a point by exaggerating some aspects of Emacs
and presenting others as hopelessly outdated.  I invite you to read
the code and make up your own mind.

> So I ask: is it possible that Emacs' GUI be decoupled from the lisp core 
> such that updates can happen as fast as possible (less perceived delay), 
> and that the (what I gather from the above post) rube goldberg display 
> internals be remade from scratch, or more likely, a new frontend (from 
> scratch) as an alternative?

I don't know if it's possible.  I do know that it is very hard,
because Emacs wants to control the GUI completely -- and it must do so
to let our users do the crazy, sometimes insane, stuff by writing
relatively simple Lisp.  If someone knows how to decouple while
keeping what makes Emacs Emacs -- such ideas, let alone code, will be
very welcome.

> Besides the criticisms: Emacs, so far, is amazing. I can make it do 
> whatever I want, however I want, and mould it to be uniquely my own 
> which is something I cannot do with anything else. The effort from 
> scores of people over ~40 years as well as the continued effort shows. I 
> can't imagine so much effort or such an enduring project.

You need to understand that this comes at a price.  As the saying
goes, "the impossible we do immediately; miracles take a little
longer".  Eventually, the insane amount of processing Emacs needs to
do in order to provide the expected flexibility and control hits the
bare machine performance wall.  When that happens, my best advice is
to buy a faster machine and/or optimize the optional features you turn
ON.

Happy hacking!



  parent reply	other threads:[~2024-10-20 19:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-20 18:46 Emacs graphical frontends / responsiveness Jordan Ellis Coppard
2024-10-20 19:11 ` Corwin Brust
2024-10-20 19:30 ` Eli Zaretskii [this message]
2024-10-20 19:39 ` Suhail Singh
2024-10-20 21:49 ` Ship Mints
2024-10-21  1:39 ` Sean Whitton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=861q0ainco.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=jc+o.emacs@wz.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.