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

From: Steven Allen <[email-masked]>
Date: Wed, 06 Aug 2025 09:32:19 -0700

Juri Linkov <[email-masked]> writes:
> Instead of reverting the change maybe it would be better to add
> a customizable cache function that anyone could change to adapt caching
> to own needs by adding more cache keys such as e.g. '(selected-frame)',
> '(face-all-attributes 'default)', 'face-remapping-alist', ...

That's going to lead to a very poor user experience; we can't reasonably
ask users just "figure it out". I'd be less concerned if this were just
a weird edge-case, but causes issues with `global-text-scale-adjust'.

I've looked into what it would take to make a bug-free cache without
modifying Emacs core and/or advice, and it's not simple. You'd need to
use `object-intervals' to extract all the face properties, then parse
the face properties to extract the faces (both inline faces and named
faces), then use face-all-attributes to extract the attributes. At that
point, you might as well just recompute the width.

If modifying Emacs core is on the table, the simplest solution I can
think of is to:

1. Have a per-frame cache.
2. Update a global `face-modification-tick' (similar to
`buffer-modification-tick') whenever faces are updated, invalidating the
cache whenever this changes.

Unfortunately, that second part would likely require modifying
`internal-set-lisp-face-attribute' (in C) and it feels kind of icky. On
the other hand, having the ability to detect that faces have changed
_is_ kind of useful.