From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 68006@debbugs.gnu.org
Subject: bug#68006: 30.0.50; Image-mode speed
Date: Tue, 26 Dec 2023 15:45:11 +0100 [thread overview]
Message-ID: <87bkadyqdk.fsf@ledu-giraud.fr> (raw)
In-Reply-To: <83bkae9j11.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 25 Dec 2023 21:30:50 +0200")
[-- Attachment #1: Type: text/plain, Size: 769 bytes --]
Eli Zaretskii <eliz@gnu.org> writes:
>> From: Manuel Giraud <manuel@ledu-giraud.fr>
>> Cc: 68006@debbugs.gnu.org
>> Date: Mon, 25 Dec 2023 19:59:10 +0100
>>
>> About being sure to display the file on disk, maybe we could call
>> 'image-flush' only if the file has changed since its display. WDYT?
>
> Provided that the check is reliable, I guess so.
>
> In any case, I think we should be cautious and leave a knob to get
> back the old behavior, in case there are some situations we don't
> anticipate that need to flush the caches.
Hi,
What do you think of this? Of course, it will need a NEWS entry but I
wanted to polish it first. I have made it opt-in. I have used it a bit
the cache could grow fast but I find it quite pleasant to use (for
Docview also).
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-some-user-control-on-image-caching.patch --]
[-- Type: text/x-patch, Size: 3032 bytes --]
From 4f941c1fe7bc91b121f305b3a3239cf9a3944a6b Mon Sep 17 00:00:00 2001
From: Manuel Giraud <manuel@ledu-giraud.fr>
Date: Tue, 26 Dec 2023 15:35:17 +0100
Subject: [PATCH] Add some user control on image caching
* lisp/image-mode.el (image-eager-flush): New custom to control
image cache flush.
(image-toggle-display-image): Flush image upon on file disk
change.
* src/image.c (Fimage_timestamp): New function to access image
display timestamp.
---
lisp/image-mode.el | 16 ++++++++++++++--
src/image.c | 25 +++++++++++++++++++++++++
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/lisp/image-mode.el b/lisp/image-mode.el
index d5ca6348c92..ccea96ecc26 100644
--- a/lisp/image-mode.el
+++ b/lisp/image-mode.el
@@ -93,6 +93,12 @@ image-auto-resize-on-window-resize
:version "27.1"
:group 'image)
+(defcustom image-eager-flush t
+ "Non-nil means flush image from cache eagerly."
+ :type 'boolean
+ :version "30.1"
+ :group 'image)
+
(defvar-local image-transform-resize nil
"The image resize operation.
Non-nil to resize the image upon first display.
@@ -954,8 +960,14 @@ image-toggle-display-image
(plist-put (cdr image) :width
(plist-get (cdr image) :max-width)))))
- ;; Discard any stale image data before looking it up again.
- (image-flush image)
+ ;; Discard image data if its file has changed on disk.
+ (when (or image-eager-flush
+ (and filename
+ (time-less-p
+ (image-timestamp image)
+ (file-attribute-modification-time
+ (file-attributes filename)))))
+ (image-flush image))
(setq image (append image (image-transform-properties image)))
(setq props
`(display ,image
diff --git a/src/image.c b/src/image.c
index 651ec0b34e5..3c2697d1e6f 100644
--- a/src/image.c
+++ b/src/image.c
@@ -1650,6 +1650,30 @@ DEFUN ("image-metadata", Fimage_metadata, Simage_metadata, 1, 2, 0,
return ext;
}
+DEFUN ("image-timestamp", Fimage_timestamp, Simage_timestamp, 1, 2, 0,
+ doc: /* Return the time in seconds at which the image SPEC was
+last displayed.
+
+FRAME is the frame on which the image was displayed. FRAME nil or
+omitted means use the selected frame. */)
+ (Lisp_Object spec, Lisp_Object frame)
+{
+ Lisp_Object timestamp;
+
+ timestamp = Qnil;
+ if (valid_image_p (spec))
+ {
+ struct frame *f = decode_window_system_frame (frame);
+ ptrdiff_t id = lookup_image (f, spec, -1);
+ struct image *img = IMAGE_FROM_ID (f, id);
+
+ if (img)
+ timestamp = make_lisp_time (img->timestamp);
+ }
+
+ return timestamp;
+}
+
\f
/***********************************************************************
Image type independent image structures
@@ -12908,6 +12932,7 @@ syms_of_image (void)
defsubr (&Simage_size);
defsubr (&Simage_mask_p);
defsubr (&Simage_metadata);
+ defsubr (&Simage_timestamp);
defsubr (&Simage_cache_size);
defsubr (&Simagep);
--
2.43.0
[-- Attachment #3: Type: text/plain, Size: 18 bytes --]
--
Manuel Giraud
next prev parent reply other threads:[~2023-12-26 14:45 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-24 16:44 bug#68006: 30.0.50; Image-mode speed Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-24 17:01 ` Eli Zaretskii
2023-12-25 10:34 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-25 13:36 ` Eli Zaretskii
2023-12-25 18:59 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-25 19:30 ` Eli Zaretskii
2023-12-26 14:45 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-12-26 17:15 ` Eli Zaretskii
2023-12-26 18:07 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-26 18:43 ` Eli Zaretskii
2023-12-27 12:13 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-27 13:36 ` Eli Zaretskii
2023-12-29 11:11 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-29 12:13 ` Eli Zaretskii
2023-12-30 11:36 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-30 12:37 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-12-30 23:57 ` Stefan Kangas
2023-12-31 7:16 ` Eli Zaretskii
2024-01-02 0:19 ` Stefan Kangas
2024-01-02 12:10 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-02 12:49 ` Eli Zaretskii
2024-01-02 16:04 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-02 17:02 ` Eli Zaretskii
2024-01-04 16:47 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-04 17:43 ` Eli Zaretskii
2024-01-04 18:42 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-04 18:55 ` Eli Zaretskii
2024-01-04 19:16 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-04 19:54 ` Eli Zaretskii
2024-01-05 10:50 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-05 11:25 ` Eli Zaretskii
2024-01-05 13:26 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-05 13:40 ` Eli Zaretskii
2024-01-05 14:35 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-05 14:41 ` Eli Zaretskii
2024-01-05 14:54 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-06 13:07 ` Manuel Giraud via Bug reports for GNU Emacs, the Swiss army knife of text editors
2024-01-01 10:10 ` 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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87bkadyqdk.fsf@ledu-giraud.fr \
--to=bug-gnu-emacs@gnu.org \
--cc=68006@debbugs.gnu.org \
--cc=eliz@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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).