unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Alan Mackenzie <acm@muc.de>
To: Eli Zaretskii <eliz@gnu.org>
Cc: rudalics@gmx.at, dancol@dancol.org, monnier@iro.umontreal.ca,
	rms@gnu.org, emacs-devel@gnu.org
Subject: Re: cc-mode fontification feels random
Date: Wed, 9 Jun 2021 21:03:03 +0000	[thread overview]
Message-ID: <YMEshwYCfTTG2Rjp@ACM> (raw)
In-Reply-To: <83pmwudgw3.fsf@gnu.org>

Hello, Eli.

On Wed, Jun 09, 2021 at 21:36:44 +0300, Eli Zaretskii wrote:
> > Date: Wed, 9 Jun 2021 18:22:57 +0000
> > Cc: Daniel Colascione <dancol@dancol.org>, monnier@iro.umontreal.ca,
> >   rudalics@gmx.at, emacs-devel@gnu.org, rms@gnu.org
> > From: Alan Mackenzie <acm@muc.de>

> > > I think we agree.  Except that for me, it should also not try if it
> > > cannot do it quickly enough, not only reliably enough.

> > Quickly and reliably enough are desirable things, but in competition
> > with eachother.  Reliably enough is a lot easier to measure, quickly
> > enough depends on the machine, the degree of optimisation, and above
> > all, the user's expectations.

> That's why we had (and still have) font-lock-maximum-decoration: so
> that users could control the tradeoff.  Unfortunately, support for
> that variable is all but absent nowadays, because of the widespread
> mistaken assumption that font-lock is fast enough in all modes.

That variable is still supported by CC Mode (with the exception of AWK
Mode, where it surely is not needed).

Another possibility would be to replace accurate auxiliary functionality
with rough and ready facilities.  In a scroll through xdisp.c, fontifying
as we go, the following three functions are taking around 30% of the
run-time:

(i) c-bs-at-toplevel-p, which determines whether or not a brace is at the
  top level.
(ii) c-determine-limit, c-determine-+ve-limit, which determine search
  limits approximately ARG non-literal characters before or after point.

By replacing these accurate functions with rough ones, the fontification
would be right most of the time, but a mess at other times (for example,
when there are big comments near point).  (i) is more important for C++
that C, but still makes a difference in C.

If we were to try this, I think a user toggle would be needed.

> > > > IMHO, we should rely on LSP to figure out what symbols are types, and if 
> > > > a LSP isn't available, we shouldn't try to guess.

> > "Shouldn't try to guess" means taking a great deal of
> > font-lock-type-faces out of CC Mode.  I don't honestly think the end
> > result would be any better than what we have at the moment.

> You don't think it will be better for what reason?

Because many users will still want at least the basic types (int, double,
unsigned long, ....) fontified, leading to the very mess Daniel would
like to avoid.   Declarations with basic types tend to be interleaved
with those using project defined types.

> > > I was talking about what to do (or not to do) with our existing
> > > regexp- and "syntax"-based fontifications.  I still remember the days
> > > when CC Mode handled that well enough without being a snail it
> > > frequently is now, and that was on a machine about 10 times slower
> > > than the one I use nowadays.

> > Those old versions had masses of fontification bugs in them.

> I don't remember bumping into those bugs.  Or maybe they were not
> important enough to affect my UX.  Slow redisplay, by contrast, hits
> me _every_day_, especially if I need to work with an unoptimized
> build.  From where I stand, the balance between performance and
> accuracy have shifted to the worse, unfortunately.

OK.  My above suggestion might give ~50% increase in fontification speed.

> > People wrote bug reports about them and they got fixed.  Those fixes
> > frequently involved a loss of speed.  :-(

> If there's no way of fixing a bug without adversely affecting speed,
> we should add user options to control those "fixes", so that people
> could choose the balance that fits them.

I think this would be a bad thing.  There are no (or very few) similar
user options in CC Mode at the moment, and an option to fix or not fix a
bug seems a strange idea, and would make the code quite a bit more
complicated.

> Sometimes Emacs could itself decide whether to invoke the "slow" code.
> For example, it makes no sense for users of C to be "punished" because
> we want more accurate fontification of C++ sources.

There is some truth in this imputation, yes.

> > There have also been several bug reports about unusual buffers
> > getting fontified at the speed of continental drift, and fixing those
> > has usually led to a little slowdown for ordinary buffers.  I'm
> > thinking, for example, about bug #25706, where a 4 MB file took
> > nearly an hour to scroll through on my machine.  After the fix, it
> > took around 86 seconds.

> Once again, a pathological use case should not punish the usual ones;
> if the punishment is too harsh, there should be a way to disable the
> support for pathological cases for those who never hit them.

The punishment is rarely too harsh for a single bug.  But a lot of 2%s,
3%s or 5%s add up over time.  If we were to outlaw a "3% fix", then many
bugs would just be unsolvable.

> > > The C language didn't change too much since then, at least not the
> > > flavor I frequently edit.

> > There are two places where CC Mode can be slow: font locking large areas
> > of text, and keeping up with somebody typing quickly.  Which of these
> > bothers you the most?  I have plans for speeding up one of these.

> Both, I guess.  Though the former is probably more prominent, since
> I'm not really such a fast typist, but I do happen to scroll through
> source quite a lot.

Thanks.  I'll try to come up with speedups in the coming weeks (and
months).

Do you have fast-but-imprecise-scrolling enabled?  That can reduce the
pain.

-- 
Alan Mackenzie (Nuremberg, Germany).



  parent reply	other threads:[~2021-06-09 21:03 UTC|newest]

Thread overview: 274+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04  3:16 cc-mode fontification feels random Daniel Colascione
2021-06-04  6:10 ` Eli Zaretskii
2021-06-04  7:10   ` Theodor Thornhill
2021-06-04 10:08     ` João Távora
2021-06-04 10:39       ` Eli Zaretskii
2021-06-04 10:59         ` Philipp
2021-06-04 11:05           ` João Távora
2021-06-04 11:22             ` Eli Zaretskii
2021-06-04 12:44               ` Dmitry Gutov
2021-06-04 13:46               ` João Távora
2021-06-04 14:11                 ` Eli Zaretskii
2021-06-04 11:18           ` Eli Zaretskii
2021-06-04 16:43       ` Jim Porter
     [not found]         ` <83k0n9l9pv.fsf@gnu.org>
2021-06-04 19:41           ` Jim Porter
2021-06-04 19:53             ` Eli Zaretskii
2021-06-04 20:05               ` Jim Porter
2021-06-04 20:11                 ` Joost Kremers
2021-06-05  6:51                   ` Eli Zaretskii
2021-06-05 10:14                     ` Joost Kremers
2021-06-05 11:31                       ` Eli Zaretskii
2021-06-05 12:12                         ` Joost Kremers
2021-06-05 13:23                     ` Stefan Monnier
2021-06-05 17:08                       ` Óscar Fuentes
2021-06-05 17:31                         ` Stefan Monnier
2021-06-05 17:32                         ` Eli Zaretskii
2021-06-05 18:46                     ` João Távora
2021-06-05  6:41                 ` Eli Zaretskii
2021-06-05  9:32                   ` João Távora
2021-06-05  9:59                     ` Ergus
2021-06-05 11:29                       ` Eli Zaretskii
2021-06-05 11:55                         ` Daniel Colascione
2021-06-05 12:27                           ` Eli Zaretskii
2021-06-05 17:59                             ` Jim Porter
2021-06-05 18:56                               ` Daniel Martín
2021-06-05 12:43                         ` Ergus
2021-06-05 13:59                       ` Remote GUI Emacs really works (was: cc-mode fontification feels random) Óscar Fuentes
2021-06-05 11:25                     ` cc-mode fontification feels random Eli Zaretskii
2021-06-05  9:46                   ` Ergus
2021-06-05 11:27                     ` Eli Zaretskii
2021-06-04 20:14               ` Yuri Khan
2021-06-04 10:25     ` Eli Zaretskii
2021-06-04 10:05   ` Daniel Colascione
2021-06-04 10:22     ` Eli Zaretskii
2021-06-04 10:34       ` João Távora
2021-06-04 10:43         ` Eli Zaretskii
2021-06-04 18:25         ` Stefan Monnier
2021-06-04 18:36           ` Daniel Colascione
2021-06-04 19:11             ` Eli Zaretskii
2021-06-04 19:16               ` Daniel Colascione
2021-06-04 19:26                 ` Eli Zaretskii
2021-06-04 19:33                   ` Daniel Colascione
2021-06-04 19:51                     ` Eli Zaretskii
2021-06-05  0:29             ` Stefan Monnier
2021-06-05  6:32               ` Eli Zaretskii
2021-06-04 19:07           ` Eli Zaretskii
2021-06-04 19:26             ` Daniel Colascione
2021-06-04 19:32               ` Eli Zaretskii
2021-06-04 10:41       ` Eli Zaretskii
2021-06-04 10:42 ` Ergus
2021-06-04 15:54 ` Alan Mackenzie
2021-06-04 18:30   ` Daniel Colascione
2021-06-06 11:37     ` Alan Mackenzie
2021-06-06 11:57       ` Eli Zaretskii
2021-06-06 12:27         ` Alan Mackenzie
2021-06-06 12:44           ` Eli Zaretskii
2021-06-06 14:19             ` Alan Mackenzie
2021-06-06 17:06               ` Eli Zaretskii
2021-06-06 17:44       ` Stefan Monnier
2021-06-06 18:00         ` Eli Zaretskii
2021-06-06 18:18           ` Stefan Monnier
2021-06-06 18:33             ` Daniel Colascione
2021-06-06 20:24               ` Stefan Monnier
2021-06-06 20:27                 ` Daniel Colascione
2021-06-06 20:38                   ` Stefan Monnier
2021-06-06 19:03             ` Eli Zaretskii
2021-06-06 20:28               ` Stefan Monnier
2021-06-07  7:35                 ` martin rudalics
2021-06-07 13:20                   ` Stefan Monnier
2021-06-07 13:37                     ` Eli Zaretskii
2021-06-08  0:06                       ` Daniel Colascione
2021-06-08 15:16                       ` Stefan Monnier
2021-06-07 15:58                     ` martin rudalics
2021-06-08  4:01                     ` Richard Stallman
2021-06-08 15:29                       ` Stefan Monnier
2021-06-08 15:52                         ` Eli Zaretskii
2021-06-08 16:36                           ` Stefan Monnier
2021-06-08 18:11                             ` Daniel Colascione
2021-06-08 18:25                               ` Eli Zaretskii
2021-06-08 18:28                                 ` Daniel Colascione
2021-06-08 18:54                                   ` Eli Zaretskii
2021-06-09 18:22                                 ` Alan Mackenzie
2021-06-09 18:36                                   ` Eli Zaretskii
2021-06-09 18:51                                     ` Daniel Colascione
2021-06-09 19:04                                       ` Eli Zaretskii
2021-06-09 20:07                                       ` chad
2021-06-10  6:43                                         ` Eli Zaretskii
2021-06-09 20:17                                       ` Dmitry Gutov
2021-06-09 21:03                                     ` Alan Mackenzie [this message]
2021-06-10  2:21                                       ` Daniel Colascione
2021-06-10  6:55                                         ` Eli Zaretskii
2021-06-10  6:58                                           ` Daniel Colascione
2021-06-10  7:19                                             ` Eli Zaretskii
2021-06-10  6:39                                       ` Eli Zaretskii
2021-06-10 16:46                                         ` Alan Mackenzie
2021-06-10 17:01                                           ` Eli Zaretskii
2021-06-10 17:07                                             ` Daniel Colascione
2021-06-10 17:22                                               ` Eli Zaretskii
2021-06-10 17:33                                                 ` Daniel Colascione
2021-06-10 17:39                                                   ` Eli Zaretskii
2021-06-10 17:40                                                 ` Óscar Fuentes
2021-06-10 17:44                                                   ` Eli Zaretskii
2021-06-11 16:11                                                 ` Alan Mackenzie
2021-06-11 17:53                                                   ` Eli Zaretskii
2021-06-11 18:02                                                     ` Daniel Colascione
2021-06-11 18:22                                                       ` Eli Zaretskii
2021-06-11 18:28                                                         ` Daniel Colascione
2021-06-11 19:12                                                           ` Alan Mackenzie
2021-06-11 19:23                                                           ` Eli Zaretskii
2021-06-11 18:47                                                         ` Alan Mackenzie
2021-06-11 19:32                                                           ` Eli Zaretskii
2021-06-11 19:46                                                             ` Alan Mackenzie
2021-06-11 19:50                                                               ` Eli Zaretskii
2021-06-11 18:42                                                       ` Stefan Monnier
2021-06-11 19:31                                                         ` Eli Zaretskii
2021-06-11 19:57                                                           ` Stefan Monnier
2021-06-11 23:25                                                             ` Ergus
2021-06-11 23:52                                                               ` Óscar Fuentes
2021-06-12  1:08                                                                 ` Ergus
2021-06-12  3:20                                                                   ` Stefan Monnier
2021-06-12 11:07                                                                     ` Ergus
2021-06-12  6:58                                                                   ` Eli Zaretskii
2021-06-12 11:01                                                                     ` Ergus
2021-06-12 11:25                                                                       ` Eli Zaretskii
2021-06-12 15:04                                                                         ` Ergus
2021-06-12 15:16                                                                           ` Eli Zaretskii
2021-06-12 15:23                                                                             ` Ergus
2021-06-12 15:35                                                                               ` Eli Zaretskii
2021-06-12 14:00                                                                     ` Stefan Monnier
2021-06-12 14:20                                                                       ` Eli Zaretskii
2021-06-12 14:33                                                                         ` Stefan Monnier
2021-06-12 15:06                                                                           ` Eli Zaretskii
2021-06-12 15:46                                                                             ` Stefan Monnier
2021-06-12  6:50                                                                 ` Eli Zaretskii
2021-06-12  5:20                                                               ` Theodor Thornhill
2021-06-12 13:40                                                                 ` Stefan Monnier
2021-06-12 15:56                                                                   ` Theodor Thornhill
2021-06-12 16:59                                                                     ` Ergus
2021-06-12 17:51                                                                       ` Theodor Thornhill
2021-06-12 17:25                                                                     ` Stefan Monnier
2021-06-12 17:53                                                                       ` Theodor Thornhill
2021-06-12 17:54                                                                       ` Ergus
2021-06-12 18:02                                                                       ` Daniel Colascione
2021-06-12 18:39                                                                         ` Ergus
2021-06-12  6:38                                                             ` Eli Zaretskii
2021-06-12 13:44                                                               ` Stefan Monnier
2021-06-12 14:14                                                                 ` Eli Zaretskii
2021-06-11 20:06                                                           ` Alan Mackenzie
2021-06-12  6:44                                                             ` Eli Zaretskii
2021-06-12  8:00                                                               ` Daniel Colascione
2021-06-12  8:08                                                                 ` Eli Zaretskii
2021-06-12  9:31                                                                   ` Alan Mackenzie
2021-06-11 19:48                                                         ` Eli Zaretskii
2021-06-11 18:34                                                     ` Alan Mackenzie
2021-06-10 17:26                                               ` Óscar Fuentes
2021-06-10 17:39                                               ` andrés ramírez
2021-06-10 21:06                                           ` Stefan Monnier
2021-06-11  6:14                                             ` Eli Zaretskii
2021-06-10 15:16                                       ` Ergus
2021-06-10 15:34                                         ` Óscar Fuentes
2021-06-10 19:06                                           ` Ergus
2021-06-10 19:28                                             ` Eli Zaretskii
2021-06-10 21:56                                               ` Ergus
2021-06-10 15:59                                         ` Jim Porter
2021-06-10 21:02                                         ` Stefan Monnier
2021-06-11 20:21                                           ` Ergus
2021-06-11 20:27                                             ` Stefan Monnier
2021-06-11 20:37                                               ` Daniel Colascione
2021-06-11 20:52                                                 ` Stefan Monnier
2021-06-12  6:46                                                   ` Eli Zaretskii
2021-06-12  8:03                                                     ` Daniel Colascione
2021-06-12  8:13                                                       ` Eli Zaretskii
2021-06-12 13:51                                                       ` Stefan Monnier
2021-06-12  8:47                                                   ` Daniele Nicolodi
2021-06-12  8:57                                                     ` tomas
2021-06-12 14:04                                                     ` Stefan Monnier
2021-06-09 19:05                                   ` Daniel Colascione
2021-06-09 19:11                                     ` Eli Zaretskii
2021-06-09 20:20                                     ` Alan Mackenzie
2021-06-09 20:36                                       ` Stefan Monnier
2021-06-10  7:01                                         ` Daniel Colascione
2021-06-10  7:21                                           ` Eli Zaretskii
2021-06-10  2:21                                       ` Daniel Colascione
2021-06-19  9:25                                         ` Alan Mackenzie
2021-06-19 15:24                                           ` Alan Mackenzie
2021-07-09 14:06                                             ` Daniel Colascione
2021-07-11 18:12                                               ` Stephen Leake
2021-07-15 18:13                                                 ` Perry E. Metzger
2021-07-15 22:43                                                   ` Tree Sitter (was Re: cc-mode fontification feels random) Perry E. Metzger
2021-07-19 23:49                                                     ` Stephen Leake
2021-07-20 14:53                                                       ` Perry E. Metzger
2021-07-21  0:04                                                         ` Stephen Leake
2021-07-21  1:28                                                           ` Stefan Monnier
2021-07-21 14:43                                                             ` Perry E. Metzger
2021-07-21 16:21                                                               ` Daniel Colascione
2021-07-21 19:15                                                                 ` Perry E. Metzger
2021-07-22  1:16                                                                   ` Daniel Colascione
2021-07-22 13:18                                                                     ` Perry E. Metzger
2021-07-22 13:49                                                                     ` Yuan Fu
2021-07-24 20:05                                                                     ` [SPAM UNSURE] " Stephen Leake
2021-07-25  0:41                                                                       ` Daniel Colascione
2021-07-26  4:24                                                                         ` [SPAM UNSURE] " Stephen Leake
2021-07-25 18:01                                                                       ` Perry E. Metzger
2021-07-22 14:00                                                           ` Perry E. Metzger
2021-07-24  1:17                                                             ` Richard Stallman
2021-07-25 16:13                                                               ` Stephen Leake
2021-07-25 19:52                                                                 ` Ada (was Re: Tree Sitter) Perry E. Metzger
2021-07-26  5:05                                                                   ` Stephen Leake
2021-07-26  9:42                                                                     ` Stephen Leake
2021-07-26 14:01                                                                       ` Perry E. Metzger
2021-07-26 13:45                                                                     ` Perry E. Metzger
2021-07-27  0:26                                                                   ` Richard Stallman
2021-07-27 12:38                                                                     ` Perry E. Metzger
2021-07-26  2:23                                                                 ` Tree Sitter (was Re: cc-mode fontification feels random) John Yates
2021-07-24 19:59                                                             ` Stephen Leake
2021-07-24 21:21                                                               ` OFF-TOPIC: Ada availability (was: Tree Sitter) Óscar Fuentes
2021-07-25  7:31                                                                 ` tomas
2021-06-08 18:11                             ` cc-mode fontification feels random Eli Zaretskii
2021-06-08 21:25                               ` Stefan Monnier
2021-06-09  3:39                         ` Richard Stallman
2021-06-09  8:34                         ` martin rudalics
2021-06-09 13:14                           ` `open-paren-in-column-0-is-defun-start` (was: cc-mode fontification feels random) Stefan Monnier
2021-06-09 15:15                             ` Yuri Khan
2021-06-09 15:16                               ` Yuri Khan
2021-06-12 17:29                           ` cc-mode fontification feels random João Távora
2021-06-13  8:50                             ` martin rudalics
2021-06-13  9:05                               ` João Távora
2021-06-13  9:39                                 ` martin rudalics
2021-06-13 10:06                                   ` João Távora
2021-06-13 14:52                                     ` martin rudalics
2021-06-13 15:25                                       ` João Távora
2021-06-14  8:29                                         ` martin rudalics
2021-06-14  8:40                                           ` João Távora
2021-06-14  9:00                                             ` martin rudalics
2021-06-14  9:14                                               ` João Távora
2021-06-14 11:28                                           ` Eli Zaretskii
2021-06-14 14:39                                           ` Stefan Monnier
2021-06-15 22:38                                             ` Ergus
2021-06-07 12:08                 ` Eli Zaretskii
2021-06-08 15:22                   ` Stefan Monnier
2021-06-08 15:46                     ` Eli Zaretskii
2021-06-05 20:25   ` Dmitry Gutov
2021-06-06 11:53     ` Alan Mackenzie
2021-06-06 17:08       ` Dmitry Gutov
2021-08-30 18:50 ` [PATCH] " Alan Mackenzie
2021-08-30 19:03   ` Perry E. Metzger
2021-08-30 19:18     ` Alan Mackenzie
2021-08-30 19:25   ` Eli Zaretskii
2021-08-30 19:28     ` Daniel Colascione
2021-08-30 19:37       ` Eli Zaretskii
2021-08-30 20:11       ` Stefan Monnier
2021-08-31 10:54         ` Alan Mackenzie
2021-08-31 13:23           ` Eli Zaretskii
2021-08-31 16:02             ` Alan Mackenzie
2021-08-31 16:21               ` Eli Zaretskii
2021-08-31 16:46                 ` Alan Mackenzie
2021-08-31 17:02                   ` Eli Zaretskii
2021-08-31 18:56           ` Stefan Monnier
2021-08-31 21:17             ` Alan Mackenzie
2021-08-31 21:47               ` Stefan Monnier
2021-10-22 20:13               ` [Committed PATCH] " Alan Mackenzie
2021-10-24 20:18                 ` Alan Mackenzie
2021-08-31 13:18         ` [PATCH] " Eli Zaretskii
2021-08-30 20:03     ` Alan Mackenzie
2021-08-31 11:53       ` Eli Zaretskii

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

  List information: https://www.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=YMEshwYCfTTG2Rjp@ACM \
    --to=acm@muc.de \
    --cc=dancol@dancol.org \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=rms@gnu.org \
    --cc=rudalics@gmx.at \
    /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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).