Subject: bug#16621: 24.3.50; Periodic timer + overlays = flickering near point

From: Dmitry Gutov <[email-masked]>
Date: Tue, 04 Feb 2014 04:34:58 +0200

On 02.02.2014 18:39, Eli Zaretskii wrote:
> I don't think this is related to overlays, not directly anyway.

True, I've seen it without overlays, too, recently.

> No, it doesn't stop, at least not with the above recipe.  To see that,
> type "M-x trace-redisplay RET" while running the above experiment --
> on my system, this causes the flickering to become much more prominent
> and never stop, until I exit isearch and type some simple command,
> like C-f, afterwards (to remove the echo-area message).

I wanted to say there's no such function, but apparently one has to 
compile Emacs with -DGLYPH_DEBUG to use it. I'll take your word for it.

> What you see is result of redrawing the cursor at a very high
> frequency.  Normally, redrawing the cursor would only flicker the
> character below the cursor, but with some fonts, the adjacent
> characters are also affected, if the character under the cursor
> "overhangs" to the left and/or to the right into the neighboring
> character cells -- then Emacs redraws those adjacent characters as
> well.

Isn't the fact that flickering is at all possible in this scenario, a 
problem? Doesn't it mean that occasional flickers can still happen under 
normal conditions (timers with much longer intervals, for example),just 
that the probability of occurrence is smaller. If I understand you 
right, all it takes is for timer to fire at just the right moment before 
the screen updates.

> Why is the cursor redrawn with such a high frequency, you ask?
> Because of the timer that expires every 10 msec.  When some timer
> expires, Emacs always triggers redisplay.  If it didn't, features like
> highlight-tail could not produce their effect.

Thank you, I guess that solves the immediate problem with 
highlight-tail-mode for me (lower the amount of steps, increase the 
intervals), but one of the reasons I filed this bug is I've been 
noticing occasional redisplay flickers with Emacs for as long as I can 
remember. They are a nuisance, and until now they've been impossible to 
reproduce, for me.

> With highlight-tail-mode, I see flickering only when I type text.
> This is expected, since typing text modifies the color of the overlays
> at a very high frequency (50 Hz with your customizations), which again
> requires redrawing the current line and the cursor.  If you see
> something else with highlight-tail-mode, please describe the recipe.

I do see similar flickering from time to time after I stop typing, but 
that can be chalked up to timers too, I guess. This is also harder to 
reproduce (happens not often, and in longer-living Emacs sessions).

> All of the above is quite normal, so I don't see where there would be
> a bug.  Granted, Emacs 24.3 and Emacs 23 behave the same.

Some relatively low-hanging fruit has already been mentioned in the 
comments, but would it be too much to expect some sort of 
double-buffering used for Emacs display, eventually? Or is the related 
overhead considered too much of a cost?