From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: 74537@debbugs.gnu.org
Subject: bug#74537: [PATCH] An on-disk image modification does a cache miss
Date: Mon, 25 Nov 2024 22:24:25 +0100 [thread overview]
Message-ID: <87ed2z6m7q.fsf@ledu-giraud.fr> (raw)
[-- Attachment #1: Type: text/plain, Size: 739 bytes --]
Tags: patch
Hi,
With this patch, when an image file is modified on disk, the associated
cache image is invalidated and re-read from disk.
In GNU Emacs 31.0.50 (build 4, x86_64-unknown-openbsd7.6, X toolkit) of
2024-11-23 built on computer
Repository revision: 5072b6110b69a8ba0d42772b26533dcdc39ffdfc
Repository branch: mgi/jpeg
Windowing system distributor 'The X.Org Foundation', version 11.0.12101014
System Description: OpenBSD computer 7.6 GENERIC.MP#437 amd64
Configured using:
'configure CC=egcc CPPFLAGS=-I/usr/local/include
LDFLAGS=-L/usr/local/lib MAKEINFO=gmakeinfo --prefix=/home/manuel/emacs
--bindir=/home/manuel/bin --with-x-toolkit=lucid
--with-toolkit-scroll-bars=no --without-cairo
--without-compress-install'
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-An-on-disk-image-modification-does-a-cache-miss.patch --]
[-- Type: text/patch, Size: 3296 bytes --]
From 0b0e0cbc947e357c8053c2837622094b00a422d5 Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Mon, 25 Nov 2024 17:04:03 +0100
Subject: [PATCH] An on-disk image modification does a cache miss
* src/dispextern.h: Add modification time to an image.
* src/image.c (make_image): Get the modification time from the
image file.
(lookup_image): Make a modified image on disk results in a cache
miss.
* lisp/startup.el (fancy-splash-head): Remove a non full-path
image file spec (XXX is there more?).
---
lisp/startup.el | 2 +-
src/dispextern.h | 4 ++++
src/image.c | 26 ++++++++++++++++++++++++++
3 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/lisp/startup.el b/lisp/startup.el
index 3436409a35e..42f6e70f05d 100644
--- a/lisp/startup.el
+++ b/lisp/startup.el
@@ -1957,7 +1957,7 @@ fancy-splash-image-file
(defun fancy-splash-head ()
"Insert the head part of the splash screen into the current buffer."
(let* ((image-file (fancy-splash-image-file))
- (img (create-image image-file))
+ (img (create-image (image-search-load-path image-file)))
(image-width (and img (car (image-size img))))
(window-width (window-width)))
(when img
diff --git a/src/dispextern.h b/src/dispextern.h
index 9df6eaf623a..0f91568db99 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3170,6 +3170,10 @@ reset_mouse_highlight (Mouse_HLInfo *hlinfo)
in prepare_image_for_display. */
struct timespec timestamp;
+ /* The modification time of the file of this image. Set in
+ make_image. */
+ struct timespec mtime;
+
/* Pixmaps of the image. */
Emacs_Pixmap pixmap, mask;
diff --git a/src/image.c b/src/image.c
index db7f6acd171..c5bddaf5985 100644
--- a/src/image.c
+++ b/src/image.c
@@ -37,6 +37,7 @@ Copyright (C) 1989-2024 Free Software Foundation, Inc.
#include <stdint.h>
#include <c-ctype.h>
#include <flexmember.h>
+#include <stat-time.h>
#include "lisp.h"
#include "frame.h"
@@ -1744,6 +1745,7 @@ make_image (Lisp_Object spec, EMACS_UINT hash)
{
struct image *img = xzalloc (sizeof *img);
Lisp_Object file = image_spec_value (spec, QCfile, NULL);
+ struct stat st;
eassert (valid_image_p (spec));
img->dependencies = NILP (file) ? Qnil : list1 (file);
@@ -1754,6 +1756,9 @@ make_image (Lisp_Object spec, EMACS_UINT hash)
img->ascent = DEFAULT_IMAGE_ASCENT;
img->hash = hash;
img->corners[BOT_CORNER] = -1; /* Full image */
+ /* Retrieve file mtime. */
+ if (! NILP (file) && (emacs_fstatat (AT_FDCWD, SSDATA (file), &st, 0) == 0))
+ img->mtime = get_stat_mtime (&st);
return img;
}
@@ -3513,6 +3518,27 @@ lookup_image (struct frame *f, Lisp_Object spec, int face_id)
img = NULL;
}
+ /* If the on-disk image file has changed, this is also a cache
+ miss. */
+ if (img)
+ {
+ Lisp_Object file;
+ bool found;
+
+ file = image_spec_value (spec, QCfile, &found);
+ if (found && STRINGP (file))
+ {
+ struct stat st;
+
+ if (emacs_fstatat (AT_FDCWD, SSDATA (file), &st, 0) != 0
+ || timespec_cmp (get_stat_mtime (&st), img->mtime) != 0)
+ {
+ free_image (f, img);
+ img = NULL;
+ }
+ }
+ }
+
/* If not found, create a new image and cache it. */
if (img == NULL)
{
--
2.47.0
[-- Attachment #3: Type: text/plain, Size: 18 bytes --]
--
Manuel Giraud
next reply other threads:[~2024-11-25 21:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 21:24 Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2024-11-26 13:31 ` bug#74537: [PATCH] An on-disk image modification does a cache miss Eli Zaretskii
2024-11-26 18:38 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-11-27 14:17 ` Eli Zaretskii
2024-12-10 16:42 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ed2z6m7q.fsf@ledu-giraud.fr \
--to=bug-gnu-emacs@gnu.org \
--cc=74537@debbugs.gnu.org \
--cc=manuel@ledu-giraud.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.