Subject: bug#79141: 31.0.50; The tab-bar-format-align-right cache doesn't take face changes and per-frame faces into account

From: Daniel Mendler <[email-masked]>
Date: Wed, 13 Aug 2025 13:35:03 +0200

Eli Zaretskii <[email-masked]> writes:

>> >> > Anyone who needs a (possibly unreliable) caching version, it's easy
>> >> > to create a copy of the existing 'tab-bar-format-align-right',
>> >> > add caching to it, and use in 'tab-bar-format'.
>> >>
>> >> I can describe it in this case, at least:
>> >>
>> >> 1. Any time any face attribute is updated, the "tick" would be incremented.
>> >
>> > Why do you think it makes any sense to do that?  When an attribute of
>> > any face is modified, Emacs discards and recomputes all the faces on
>> > that frame.  How would the tick help you?
>> 
>> We're caching the pixel-width of the right-aligned tab-bar segment.
>
> Ah.  But isn't it better and simpler not to cache, recomputing it anew
> each time?

Obviously simpler. In my profiling the string-pixel-width computation
took a significant fraction of the runtime.

>> Adding a `face-modification-tick' would make it possible to detect when
>> face attributes have changed, allowing us to invalidate the cached
>> width.
>
> But then whatever problems caused you to cache the pixel width will
> happen again once Emacs recomputes the faces (which happens quite
> frequently).  So I'm not sure this will be a useful feature, at least
> in your case.

Tbh I cannot really tell. My assumption was that faces are not
recomputed often, but this assumption might not be correct. Could you
clarify when face recomputations happen? Only when attributes change?
Attribute changes should not happen, right?

Daniel