Subject: bug#69385: 30.0.50; Long lines with bidi text slow down Emacs

From: Stephen Berman <[email-masked]>
Date: Mon, 26 Feb 2024 15:13:38 +0100

On Mon, 26 Feb 2024 14:33:18 +0200 Eli Zaretskii <[email-masked]> wrote:

>> From: Stephen Berman <[email-masked]>
>> Cc: [email-masked]
>> Date: Sun, 25 Feb 2024 21:36:46 +0100
[...] 
>> My CPU is Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz, certainly not
>> superfast but not superslow either, e.g. bootstrapping Emacs (without
>> native compilation) takes just a few minutes (with native compilation
>> it's a couple of minutes longer).  My HarfBuzz is version 8.3.0.
>
> The CPU is fast.  My HarfBuzz version is much older, but I doubt that
> HarfBuzz became so much slower for Arabic.  So it's very strange.  But
> maybe it's worth to try downgrading to an earlier version, just to be
> sure this is not the culprit?

That's not so straightforward on this system, where I build system
packages from source, so downgrading HarfBuzz may require also
rebuilding packages that depend on it.  I have a somewhat older system
on this machine with HarfBuzz 7.1.0, so I can easily try that.  What
version of HarfBuzz are you using?

[...]
>> Ok, I repeated the test with Hebrew without niqqud ("שלום") and indeed,
>> M-> and M-< are much quicker and even holding down C-n and C-p is
>> quicker (it does freeze, but unfreezes more quickly).  So it seems the
>> bottleneck really is the shaping.
>
> If, after starting Emacs, you set all the entries of Arabic characters
> in composition-function-table to nil (e.g., using
> set-char-table-range), do you see significant speedup?

Yes, there is a noticeable speedup when M-> and C-v, M-v, and even
holding down C-n and C-p is faster, though they still freeze after a few
seconds, but the freeze doesn't last as long as when it happens with the
shaped Arabic script.  Also, probably unsurprisingly, the speed after
disabling shaping is still much slower than keeping shaping enabled but
setting bidi-display-reordering to nil.

Steve Berman