From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#68006: 30.0.50; Image-mode speed Date: Sat, 30 Dec 2023 13:37:50 +0100 Message-ID: <87frzjvpb5.fsf@ledu-giraud.fr> References: <87le9jlfd6.fsf@ledu-giraud.fr> <83wmt3bkla.fsf@gnu.org> <87h6k6lgdy.fsf@ledu-giraud.fr> <83wmt29zfy.fsf@gnu.org> <87il4m6rcx.fsf@ledu-giraud.fr> <83bkae9j11.fsf@gnu.org> <87bkadyqdk.fsf@ledu-giraud.fr> <8334voanr1.fsf@gnu.org> <877cl0zvln.fsf@ledu-giraud.fr> <83y1dg954u.fsf@gnu.org> <87zfxvalnq.fsf@ledu-giraud.fr> <83o7eb938y.fsf@gnu.org> <87wmsxmff3.fsf@ledu-giraud.fr> <83mstt5hrk.fsf@gnu.org> Reply-To: Manuel Giraud Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="7407"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: 68006@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Dec 30 13:38:22 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1rJYbe-0001h2-EM for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Dec 2023 13:38:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rJYbL-0002Jf-H0; Sat, 30 Dec 2023 07:38:03 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rJYbK-0002JX-BL for bug-gnu-emacs@gnu.org; Sat, 30 Dec 2023 07:38:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1rJYbK-0006Hv-3F for bug-gnu-emacs@gnu.org; Sat, 30 Dec 2023 07:38:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rJYbK-0004Wi-DW for bug-gnu-emacs@gnu.org; Sat, 30 Dec 2023 07:38:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Dec 2023 12:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68006 X-GNU-PR-Package: emacs Original-Received: via spool by 68006-submit@debbugs.gnu.org id=B68006.170393988017391 (code B ref 68006); Sat, 30 Dec 2023 12:38:02 +0000 Original-Received: (at 68006) by debbugs.gnu.org; 30 Dec 2023 12:38:00 +0000 Original-Received: from localhost ([127.0.0.1]:43257 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rJYbH-0004WR-TZ for submit@debbugs.gnu.org; Sat, 30 Dec 2023 07:38:00 -0500 Original-Received: from ledu-giraud.fr ([51.159.28.247]:33478) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rJYbC-0004WF-Hi for 68006@debbugs.gnu.org; Sat, 30 Dec 2023 07:37:58 -0500 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=HXR5w0Pw /A/3pdQhOfocZYr1ipHEQtqSeoWkG8rkH5Q=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=zwWXuJpMR46HkP/Ql58Xp+Udtv8Y63 vJ9F+DoTpZk7BrXNAo6vJUP4xAXWBnsTtA5TzHIi21m9KjsJ5s5j74DQ== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=HXR5w0Pw/A/3pdQh OfocZYr1ipHEQtqSeoWkG8rkH5Q=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=Iw58XhQCRfbrTO95iFllZjLvOckbCrsEEKvckq C0RxiNzHPjNRH6gC+rvlTn/UKiUwjgJzZ7AjB37FIbOlhEUNf7mqofpjCL36ITsHOf+niE +D5h02IAucNIq5mG9n+9HYGnfw6+csemlFEszAV/Yg0WXiVrD10Zyg4Xmz5VCKMcAsrOyT GSz0NUCo0a21gE8obmzwVuyd4+T33fURO6FOGlgduE7PuaMDMQBELqzCBsIs+cO3feadIA 2AFdw/LgKzKfIZ8oSwp3oi7T8O36+wd5CkYaMU6avvRs/cKk0aUbgyhvW8zRQOJsHt6dGJ 7a4alWTU3e1NZYsthuvX10Xw== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id 4b00a024 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 30 Dec 2023 13:37:52 +0100 (CET) In-Reply-To: <83mstt5hrk.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 29 Dec 2023 14:13:03 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:277081 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii writes: >> From: Manuel Giraud >> Cc: 68006@debbugs.gnu.org >> Date: Fri, 29 Dec 2023 12:11:44 +0100 >> >> What about this new patch? It works for me as intended but might need >> better names and better docs. Thanks. >> >> +(defcustom image-mode-eager-cache-flush t >> + "Non-nil means flush image from cache eagerly. >> +When set to nil, be aware that the image cache could grow fast >> +but an image previously displayed will show faster." > > This doc string should explain the effects better, in terms of > user-facing behavior, not in terms of technical aspects of the code. And here is a new version of the patch. Maybe, we need a NEWS entry for this too. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Add-some-user-control-in-image-mode-caching.patch >From 49f1af6333b90a700c52fd4845583c0506d14795 Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Fri, 29 Dec 2023 11:48:21 +0100 Subject: [PATCH] Add some user control in image-mode caching Bug#68006 * lisp/image-mode.el (image-mode-eager-cache-flush): New custom. (image-toggle-display-image): Add a contents hash in image spec when flushing cache lazily. * lisp/image/image-dired-util.el (image-dired-thumb-name): * lisp/image.el (image-contents-sha1): Move 'image-dired-contents-sha1' to 'image-contents-sha1' in toplevel image library. --- lisp/image-mode.el | 20 ++++++++++++++++++-- lisp/image.el | 11 ++++++++++- lisp/image/image-dired-util.el | 8 +------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lisp/image-mode.el b/lisp/image-mode.el index d5ca6348c92..68be3faaae7 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -93,6 +93,16 @@ image-auto-resize-on-window-resize :version "27.1" :group 'image) +(defcustom image-mode-eager-cache-flush t + "Non-nil means an image is flushed from the cache before being +read again. When set to nil, an image spec is not removed from +the cache so it will be displayed faster the second time. + +See `image-cache-eviction-delay'." + :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 +964,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) + (if image-mode-eager-cache-flush + ;; Discard any stale image data before looking it up again. + (image-flush image) + ;; Add a content based hash into image spec to be sure that the + ;; cache is updated should the on disk image change. + (when (and filename (file-exists-p filename)) + (setq image (append image (list :hash (image-contents-sha1 filename)))))) + (setq image (append image (image-transform-properties image))) (setq props `(display ,image diff --git a/lisp/image.el b/lisp/image.el index e20fbcf4c98..0f1c74d9250 100644 --- a/lisp/image.el +++ b/lisp/image.el @@ -401,7 +401,16 @@ image-type-from-file-name ;; If nothing seems to be supported, return first type that matched. (or first (setq first type)))))))) - ;;;###autoload +;;;###autoload +(defun image-contents-sha1 (filename) + "Compute the SHA-1 of the first 4KiB of FILENAME's contents. +The first 4KiB does not represent the whole file but was chosen +because it is fast enough for interactive usage." + (with-temp-buffer + (insert-file-contents-literally filename nil 0 4096) + (sha1 (current-buffer)))) + +;;;###autoload (defun image-supported-file-p (file) "Say whether Emacs has native support for displaying TYPE. The value is a symbol specifying the image type, or nil if type diff --git a/lisp/image/image-dired-util.el b/lisp/image/image-dired-util.el index e17cc6c919f..e5f526fec57 100644 --- a/lisp/image/image-dired-util.el +++ b/lisp/image/image-dired-util.el @@ -59,12 +59,6 @@ image-dired-dir (message "Thumbnail directory created: %s" image-dired-dir)) image-dired-dir)) -(defun image-dired-contents-sha1 (filename) - "Compute the SHA-1 of the first 4KiB of FILENAME's contents." - (with-temp-buffer - (insert-file-contents-literally filename nil 0 4096) - (sha1 (current-buffer)))) - (defun image-dired-thumb-name (file) "Return absolute file name for thumbnail FILE. Depending on the value of `image-dired-thumbnail-storage' and @@ -99,7 +93,7 @@ image-dired-thumb-name (concat (md5 (concat "file://" file)) ".png") (expand-file-name thumbdir (xdg-cache-home)))) (let ((name (if (eq 'sha1-contents image-dired-thumb-naming) - (image-dired-contents-sha1 file) + (image-contents-sha1 file) ;; Defaults to SHA-1 of file name (sha1 file)))) (cond ((or (eq 'image-dired image-dired-thumbnail-storage) -- 2.43.0 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--