Subject: Re: bug#74537: [PATCH] An on-disk image modification does a cache miss

From: Eli Zaretskii <[email-masked]>
Date: Tue, 26 Nov 2024 15:31:50 +0200

> Date: Mon, 25 Nov 2024 22:24:25 +0100
> From:  Manuel Giraud via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> With this patch, when an image file is modified on disk, the associated
> cache image is invalidated and re-read from disk.

Thanks, but I'm not sure it's a good idea to do that automatically
whenever lookup_image is called.

First, lookup_image is called only when we need to create or access an
image with only its Lisp descriptor in hand; once the image has been
displayed, that should happen relatively rarely.  For example, the
glyph matrices used to manipulate the display record only the image's
cached ID, and the code accesses the cached image without calling
lookup_image.  So this change could have weird confusing effects,
whereby the fact that the image was modified on disk becomes apparent
only after some display-related actions, but not after others.  For
example, scrolling a window by a small amount will not notice the
change on disk, whereas significant changes, especially when the image
goes off the window and back into it, will show the change.  Don't you
see such issues if you install the change?

Second, if the image is already on display, and the file changes on
disk, some layout calculations could see different dimensions than
what is actually on display, which will cause subtle bugs.  For
example, what if there's a 'display' property such as this:

  '(space :width (0.5 (image PROPS)))

and an image with those same PROPS is already shown on display?  The
code which implements the above calls lookup_image, which will
simulate a cache miss if the file has changed, and will then load the
new file, which could return dimensions different from the image
already on display.  So the width of the space glyph produced by the
above will be different from that of the displayed image, and we could
have misalignment until the next redisplay which redraws the image.

So I think this should probably be controlled by a variable visible
from Lisp, by default off, and we might also have a function to
invalidate all the cached images whose files have changed (which will
then need to trigger a thorough redisplay, I think).