all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: Eli Zaretskii <eliz@gnu.org>
Cc: monnier@iro.umontreal.ca, 64596@debbugs.gnu.org
Subject: bug#64596: 30.0.50; On FIXME: in src/buffer.c:1481 (force-mode-line-update)
Date: Fri, 14 Jul 2023 13:48:43 +0000	[thread overview]
Message-ID: <87351qioxw.fsf@localhost> (raw)
In-Reply-To: <83fs5qfznv.fsf@gnu.org>

Eli Zaretskii <eliz@gnu.org> writes:

>> I'm afraid that the very existence of prevent_redisplay_optimizations_p
>> flag is a mistake hiding bugs with redisplay optimizations logic.
>
> I think you should avoid making such comments until you have a better
> understanding of the redisplay logic, or else I will stop taking your
> posts in this matter seriously.

Your answer indicates that I missed something important after reading
the top comment in xdisp.c, redisplay_internal, redisplay_window, and
skimmed through a couple of other functions. But I still cannot figure
out what.

Note that I did not mean that previous committers had bad intentions. I
just think that the idea of having "disable all optimizations" flag is
causing the code quality that could be otherwise somewhat better (at
least, more explicit about why redisplay should take long path).

I think that replacing all the instances of setting this flag to more
explicit alternatives would improve the display performance and also
readability.

>> Currently, redisplay_internal has a number of conditions used to
>> determine if one or another optimization is safe to use + assertion that
>> !prevent_redisplay_optimizations_p.
>> 
>> When some code outside xdisp.c sets this flag, it is nothing but a
>> statement: "I was lazy enough to update xdisp.c properly, so I just
>> force bypassing optimizations".
>
> No.  The optimization in question, which is disabled when
> prevent_redisplay_optimizations_p flag is set for the current buffer,
> is described in the comment before the condition:
>
>   /* Optimize the case that only the line containing the cursor in the
>      selected window has changed.
>
> The prevent_redisplay_optimizations_p flag says, among other things,
> that we are not in that case, and it is tested early enough in order
> to prevent us from examining additional conditions which are just
> waste of CPU cycles (and some of them are relatively expensive).

Sure, but it is a very generic way to say this. It provides no detailed
reason what exactly changed in the buffer/window/frame that makes us
bypass this optimization.

Is it not always possible to use the other, more specific, existing
flags for redisplay to indicate that something important has been changed?

>> So, I see not why calling bset_update_mode_line is not sufficient to
>> force mode line update in all windows associated with a single buffer.
>
> The mode line displays quite a lot of information.  It could also
> display information we don't know about (on the level of the redisplay
> code), because mode-line-format supports :eval, which can execute any
> Lisp.  Therefore, there could be changes to the buffer that affect the
> mode line indirectly.

But isn't :eval processed by display_mode_lines? Once we take care to call
bset_update_mode_line, display_mode_lines is guaranteed to be executed,
AFAIU.

> One problem of this kind which we had relatively recently is when the
> changes in mode-line-format or some of its :eval forms yields a mode
> line that is significantly taller or smaller than the previously
> displayed one.  Such changes in the mode-line height generally affect
> the window(s) as well, not just the mode line itself.

Sure, and redisplay_window accounts for this when calling display_mode_lines:

      display_mode_lines (w);
      unbind_to (count1, Qnil);

      /* If mode line height has changed, arrange for a thorough
	 immediate redisplay using the correct mode line height.  */
      if (window_wants_mode_line (w)
	  && CURRENT_MODE_LINE_HEIGHT (w) != DESIRED_MODE_LINE_HEIGHT (w))
	{
	  f->fonts_changed = true;
	  w->mode_line_height = -1;
	  MATRIX_MODE_LINE_ROW (w->current_matrix)->height
	    = DESIRED_MODE_LINE_HEIGHT (w);
	}

> Moreover, you will see in the wild that force-mode-line-update is used
> not just to update the mode line, but also to force a more thorough
> redisplay of one or more windows.

Why not `force-window-update'? 

> Thus, this is not as simple a problem as you seem to think, and we
> need deeper analysis and more significant changes than simply deleting
> the code that you didn't understand and think is redundant.  Please
> keep in mind that people who wrote that code (and I don't mean myself)
> were not stupid at all, and generally knew what they were doing!

I understand, which is why I looked into git history and found that the
code in question is carried over during refactoring. Into a new function
with different meaning.

And I now looked deeper into the code, and see no obvious downsides of
removing current_buffer->prevent_redisplay_optimizations_p = true; from
force-mode-line-update specifically.
`set-buffer-modified-p' may need to be re-considered though as it is the
original place where setting prevent_redisplay_optimizations_p was done
(for different reasons).

>> > The purpose of force-mode-line-update is to do what its name says,
>> ... 
>> Then, why do we need to call Fforce_mode_line_update in
>> set-buffer-modified-p? Wouldn't calling bset_redisplay be better?
>
> You have read the large comment there which attempts to answer this
> question, didn't you?

Yup, I did. I thought bset_redisplay as an alternative, because it is
smarter than bset_update_mode_line when the buffer is displayed in
selected window (it is not necessary to assign DISPLAY_SOME flags).

However, I did miss the docstring that explicitly says that
`set-buffer-modified-p' forces mode line update. So, forcing mode line
update here is simply following the docstring and should not be
disputed.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>





  reply	other threads:[~2023-07-14 13:48 UTC|newest]

Thread overview: 90+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-13 13:00 bug#64596: 30.0.50; On FIXME: in src/buffer.c:1481 (force-mode-line-update) Ihor Radchenko
2023-07-13 13:34 ` Eli Zaretskii
2023-07-13 17:19   ` Ihor Radchenko
2023-07-13 19:03     ` Eli Zaretskii
2023-07-14 11:53   ` Ihor Radchenko
2023-07-14 12:25     ` Eli Zaretskii
2023-07-14 13:48       ` Ihor Radchenko [this message]
2023-07-14 14:20         ` Eli Zaretskii
2023-07-14 14:50       ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-14 14:20     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-14 15:56       ` Eli Zaretskii
2023-07-13 17:20 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-13 19:08   ` Eli Zaretskii
2023-07-13 21:00     ` Ihor Radchenko
2023-07-13 22:02     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-14  6:14       ` Eli Zaretskii
2023-07-14 14:31         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-14 16:00           ` Eli Zaretskii
2023-07-14 17:38             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-14 17:46               ` Ihor Radchenko
2023-07-14 19:06                 ` Eli Zaretskii
2023-07-15  7:01                   ` Eli Zaretskii
2023-07-15  7:22                     ` Ihor Radchenko
2023-07-15  8:52                       ` Eli Zaretskii
2023-07-15 14:49                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-15 15:22                       ` Eli Zaretskii
2023-07-15 16:01                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-15 16:16                           ` Eli Zaretskii
2023-07-15 17:15                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-15 19:04                               ` Eli Zaretskii
2023-07-16 10:38                               ` Ihor Radchenko
2023-07-16 11:26                                 ` Eli Zaretskii
2023-07-15 18:15                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-15 19:18                               ` Eli Zaretskii
2023-07-15 19:28                               ` Eli Zaretskii
2023-07-15 19:43                                 ` Ihor Radchenko
2023-07-15 23:10                                   ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-16  4:57                                   ` Eli Zaretskii
2023-07-16  5:49                                     ` Ihor Radchenko
2023-07-16  7:15                                       ` Eli Zaretskii
2023-07-16  8:26                                     ` martin rudalics
2023-07-16  8:40                                       ` Ihor Radchenko
2023-07-16  8:56                                         ` Eli Zaretskii
2023-07-16  9:41                                           ` Ihor Radchenko
2023-07-16 10:30                                             ` Eli Zaretskii
2023-07-16  8:50                                       ` Eli Zaretskii
2023-07-17  8:30                                         ` martin rudalics
2023-07-15 22:53                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-16  5:17                                   ` Eli Zaretskii
2023-07-16  5:52                                   ` Ihor Radchenko
2023-07-16  7:16                                     ` Eli Zaretskii
2023-07-16  7:28                                       ` Ihor Radchenko
2023-07-16  7:35                                         ` Eli Zaretskii
2023-07-16 14:04                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-16 14:27                                       ` Eli Zaretskii
2023-07-16 14:49                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-16 10:22                       ` Ihor Radchenko
2023-07-16 10:37                         ` Eli Zaretskii
2023-07-16 10:47                           ` Ihor Radchenko
2023-07-16 11:31                             ` Eli Zaretskii
2023-07-16 14:26                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-16 14:45                               ` Eli Zaretskii
2023-07-16 16:44                                 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-16 17:11                                   ` Eli Zaretskii
2023-07-16 17:20                                     ` Eli Zaretskii
2023-07-16 18:53                                     ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-16 19:06                                       ` Eli Zaretskii
2023-07-16 22:19                                         ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-17 11:20                                           ` Eli Zaretskii
2023-07-17 12:53                                             ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-07-17 13:07                                               ` Eli Zaretskii
2023-07-16 19:27                         ` Eli Zaretskii
2023-07-16 20:12                           ` Ihor Radchenko
2023-07-17  2:23                             ` Eli Zaretskii
2023-07-17  9:22                               ` Ihor Radchenko
2023-07-17 11:54                                 ` Eli Zaretskii
2023-07-17 12:00                                   ` Ihor Radchenko
2023-07-17 12:22                                     ` Eli Zaretskii
2023-07-18  9:52                                       ` Ihor Radchenko
2023-07-18 11:51                                         ` Eli Zaretskii
2023-07-19 10:11                                           ` Ihor Radchenko
2023-07-19 14:55                                             ` Eli Zaretskii
2023-07-19 15:50                                               ` Ihor Radchenko
2023-07-19 16:30                                                 ` Eli Zaretskii
2023-07-20  9:40                                                   ` Ihor Radchenko
2023-07-20 10:23                                                     ` Eli Zaretskii
2023-07-21  2:41                                         ` Richard Stallman
2023-07-21  5:48                                           ` Eli Zaretskii
2023-07-23  3:01                                             ` Richard Stallman
2023-07-14 19:05               ` 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

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

  git send-email \
    --in-reply-to=87351qioxw.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=64596@debbugs.gnu.org \
    --cc=eliz@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.