all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Stephen Berman <stephen.berman@gmx.net>
Cc: 69385@debbugs.gnu.org
Subject: bug#69385: 30.0.50; Long lines with bidi text slow down Emacs
Date: Tue, 27 Feb 2024 10:52:23 +0200	[thread overview]
Message-ID: <86zfvmthko.fsf@gnu.org> (raw)
In-Reply-To: <87a5nmgaom.fsf@gmx.net> (message from Stephen Berman on Mon, 26 Feb 2024 22:47:21 +0100)

> From: Stephen Berman <stephen.berman@gmx.net>
> Cc: 69385@debbugs.gnu.org
> Date: Mon, 26 Feb 2024 22:47:21 +0100
> 
> I created the test buffer now by first typing "Hello" and the inserting
> " السّلام عليكم " on the right, so the base paragraph direction was LTR.
> Then I ran the benchmarks, and there is indeed a big difference, but one
> that I think will surprise you.

It doesn't, see below.

> First, the timing for the LTR run with bidi-display-reordering set
> to nil was:
> 
> (0.035104007 0 0.0)
> 
> This is, unsurprisingly, almost the same as the corresponding test run
> with RTL base paragraph direction, which was (0.034058467 0 0.0).
> 
> In contrast, recall that with bidi-display-reordering at the default
> value t, the RTL test run was (5.249231941 1 0.014300497000000023), but
> now the LTR test run gave this:
> 
> (10.613699099 1 0.012965359999999981)

Yes, that's the result of the fix I installed yesterday: it makes the
display correct, but it costs more CPU, sometimes much more.

To see why this is so costly, disable auto-composition-mode in the
buffer, and compare the times with bidi-display-reordering nil and
non-nil.  With auto-composition-mode disabled, you see the effect of
the reordering alone (because characters are still reordered for
display, just not shaped correctly, as C-f will show you), and it
should be quite small; at least, that's what I see here.  The
(mandatory) shaping of Arabic text is what takes most of the redisplay
time in these cases.  In particular, M-> does a recenter to show EOB
nicely, and that is very expensive in this case; disable that
recentering by using "(goto-char (point-max))" instead to see the
difference.

> The buffer size here is considerably larger than the buffers for my test
> runs; I couldn't remember it exactly, so I typed `M-: (point)' in the
> buffer, with the result 43901.  It took a number of seconds for the
> result to be displayed, during which Emacs was unresponsive, so I then
> ran (benchmark-run nil (point)) in that buffer, with this result:
> 
> (9.030000000000001e-07 0 0.0)
> 
> I don't know what this result means, but the reported execution time
> bears no relation to actual elapsed time until the value of point was
> displayed.  So I reran the benchmark and also manually timed it with a
> stopwatch.  This is the result of the second benchmark:
> 
> (3.1120000000000004e-06 0 0.0)
> 
> However, the stopwatch showed fully 15 seconds.  Maybe benchmark-run
> doesn't work for point for some reason.

A Lisp program that just calls '(point)' doesn't include the redisplay
caused by "M-:", which enters the minibuffer, and therefore triggers a
fairly thorough redisplay of the window, and by display of the result.
That's Emacs's MVC design in action for you.

> This sounds plausible, but my results seem to indicate there something
> else (or more) going on.

Yes: that something is character composition, which in the case of
Arabic text is quite expensive, because every chunk of Arabic text
between SPACEs goes through the shaping engine.

(This explains well why Emacs tries so hard to call the shaper only
when absolutely necessary, contrary to HarfBuzz folks' opinions that
we should pass all the text through the shaping engine, to get correct
display with ligatures, kerning, and other niceties.  They are right,
of course, but with the way character composition was designed in
Emacs, doing so would be prohibitive from the performance POV.)

> > I will see if we can do better in this matter.
> 
> I appreciate whatever you can do.

From what I've seen so far, it won't be easy, because it requires
changes to some key logic in the display code.  Hmm...





  reply	other threads:[~2024-02-27  8:52 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-25 16:23 bug#69385: 30.0.50; Long lines with bidi text slow down Emacs Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-25 17:06 ` Eli Zaretskii
2024-02-25 18:03   ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-25 19:31     ` Eli Zaretskii
2024-02-25 20:36       ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-26 12:33         ` Eli Zaretskii
2024-02-26 14:13           ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-26 14:19             ` Eli Zaretskii
2024-02-26 14:22               ` Eli Zaretskii
2024-02-26 15:17                 ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-26 15:52                   ` Eli Zaretskii
2024-02-26 15:59                     ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-26 16:36                       ` Eli Zaretskii
2024-02-26 17:12                         ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-26 19:18                           ` Eli Zaretskii
2024-02-26 21:47                             ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-27  8:52                               ` Eli Zaretskii [this message]
2024-02-27 10:13                                 ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-03 15:18                             ` Eli Zaretskii
2024-03-04 13:28                               ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-04 14:43                                 ` Eli Zaretskii
2024-03-07 11:12                                   ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-03-07 11:25                                     ` Eli Zaretskii
2024-03-21  8:29                                     ` Eli Zaretskii
2024-03-21 15:08                                       ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-02-26 15:17               ` Stephen Berman via Bug reports for GNU Emacs, the Swiss army knife of text editors

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=86zfvmthko.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=69385@debbugs.gnu.org \
    --cc=stephen.berman@gmx.net \
    /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.