Subject: Re: bug#78861: [PATCH] Avoid calendar flicker

From: Stephen Berman <[email-masked]>
Date: Sun, 22 Jun 2025 15:55:26 +0200

On Sun, 22 Jun 2025 16:05:50 +0300 Eli Zaretskii <[email-masked]> wrote:

>> From: Manuel Giraud <[email-masked]>
>> Cc: [email-masked]
>> Date: Sun, 22 Jun 2025 13:46:28 +0200
>> 
>> Eli Zaretskii <[email-masked]> writes:
>> 
>> >> From: Manuel Giraud <[email-masked]>
>> >> Date: Sun, 22 Jun 2025 09:00:02 +0200
>> >> 
>> >> When you have diary marks activated in the calendar (with 'm',
>> >> diary-mark-entries) and when moving around (for example with '<' and
>> >> '>') you will see some flicker on dates where you have marks.
>> >
>> > Please elaborate: which part(s) of the display flicker?  I tried a
>> > simple recipe to reproduce the problem, and saw no flickering on my
>> > system.
>> 
>> I see the date digits flicker when moving: the digits glimpse in black
>> before turning to red (with default theme).
>
> I don't see anything like that here.
>
>> Here is a recipe:
>>      - emacs -Q
>>      - Open "/tmp/diary" and insert the following content:
>> --8<---------------cut here---------------start------------->8---
>> %%(diary-block 6 22 2025 8 30 2025) Looong break
>> --8<---------------cut here---------------end--------------->8---
>>      - M-: (setq diary-file "/tmp/diary") <RET>
>>      - M-x calendar <RET>
>>      - Hit 'm' and then alternatively '>' and '<' to see the flicker
>
> I see the entire window being redrawn, so it's hard to see a flicker.
> Seeing flickering requires that everything stays the same and in the
> same position in the window, otherwise it's impossible to say that
> there's flickering when everything moves and changes.
>
> If the above is the best scenario you can offer, then please point me
> to the code in calendar that first draws the numbers in black and then
> redraws them in red, and I will take a look.

I don't see any flickering or redrawing with that recipe, but in my
calendar and diary configuration I do see what looks like delayed
fontification of certain date marking.  I've narrowed the issue down to
a combination of marking lunar phases and having a sufficiently large
number of diary entries (in my case due to including several todo-mode
files).  Here is a recipe:

0. Make ~/.emacs.d/diary consist of the following lines:
-------------------------------
%%(diary-lunar-phases 'warning)
Jun 22, 2025 test
-------------------------------
and then repeat the second line a large number of times (5000 shows the
issue clearly on my machine, 1000 shows it too, but not as clearly).
1. emacs -Q
2. M-x calendar
3. Hit 'm' and then alternatively '>' and '<'.

On typing 'm' there is a noticeable delay before the dates are marked,
on the first scroll command also a noticeable delay but not as long, on
subsequent scroll commands much less delay but enough to see the dates
first with default face, then change to warning face.  With Manuel's
patch let-binding 'inhibit-redisplay', there are still delays when
scrolling but the lunar phase dates are shown in warning face as soon as
the scroll happens.

>> > And what is the state of double-buffering in the session where you saw
>> > it?
>> 
>> I'm not sure but I think I'm good.  Here's an excerpt of xdpyinfo:
>
> No, I meant whether your build is with double-buffering?

Here (GNU/Linux) `M-: (x-double-buffered-p)' returns t.

Steve Berman