Subject: Re: bug#10835: 24.0.93; bidi-paragraph-direction slows down Shell mode

From: Eli Zaretskii <[email-masked]>
Date: Sat, 18 Feb 2012 10:49:19 +0200

> From: Chong Yidong <[email-masked]>
> Cc: [email-masked]
> Date: Sat, 18 Feb 2012 11:37:33 +0800
> 
> Chong Yidong <[email-masked]> writes:
> 
> > I just noticed that when I do `ls --color=no' rather than just `ls',
> > insertion and scrolling are very fast.  The sluggishness only appears
> > when ls color highlighting is enabled.  So the inefficiency of
> > ansi-color.el, and its use of overlays, seems to play a role.
> 
> I just confirmed that the sluggishness goes away if I change
> ansi-color.el to make it use text properties.

That figures.  bidi.c needs to look up display properties and overlays
with display strings, in order to DTRT with their display (they are
treated as a single neutral character).  So having lots of overlays
slows down redisplay a bit more.

> Wish I'd remembered to do that before the pretest began.

If this is a grave problem, we can still do it now, I think.  Or we
could use a band-aid, see below.

> Roughly what is happening, I think, is that when overlays are heavily
> used and there are no paragraph breaks (e.g. from the `time' output),
> the bidi code does enough the additional overlay lookups to produce a
> noticeable slowdown.

Yes, the overlays together with the long search for paragraph
beginning probably push the user experience from slightly below the
annoyance threshold to just above it.

> I'm not sure what's the best fix right now, though.

How about setting bidi-paragraph-direction in comint buffers to
left-to-right when the locale indicates that use of bidirectional
scripts is unlikely?  We could use locale-language-names and an
additional small database of languages that need bidi, to make that
decision.  WDYT?