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: Mon, 28 Oct 2024 15:31:22 +0100 Message-ID: <87zfmomh8l.fsf@ledu-giraud.fr> References: <87le9jlfd6.fsf@ledu-giraud.fr> <83r0izzn1p.fsf@gnu.org> <87le95rqoh.fsf@ledu-giraud.fr> <83plyhvvso.fsf@gnu.org> <87h6jtrlci.fsf@ledu-giraud.fr> <83jzopvsgj.fsf@gnu.org> <87bka0hpto.fsf@ledu-giraud.fr> <83il48x4a8.fsf@gnu.org> <875y08gikv.fsf@ledu-giraud.fr> <831qawvx7q.fsf@gnu.org> <871qavhpxf.fsf@ledu-giraud.fr> <83edevvqyj.fsf@gnu.org> <87v887g85d.fsf@ledu-giraud.fr> <83a5pjvo3s.fsf@gnu.org> <87a5pid2zq.fsf@ledu-giraud.fr> <87o73jf46r.fsf@ledu-giraud.fr> <86h698l9mb.fsf@gnu.org> <875xplvk77.fsf@ledu-giraud.fr> <86jze1hhj1.fsf@gnu.org> <877ca1sfcd.fsf@ledu-giraud.fr> <867ca1h69p.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="40198"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: stefankangas@gmail.com, 68006@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Oct 28 15:38:30 2024 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 1t5Qt3-000AM0-Bl for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 28 Oct 2024 15:38:29 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1t5Qo7-0003Zm-Bn; Mon, 28 Oct 2024 10:33:23 -0400 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 1t5QnC-0002ig-HQ for bug-gnu-emacs@gnu.org; Mon, 28 Oct 2024 10:32:34 -0400 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 1t5QnC-00046J-7O for bug-gnu-emacs@gnu.org; Mon, 28 Oct 2024 10:32:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=8DpZ/wStZlM5+zPediDYwZd4GBRCykONZWHuxt8lEPE=; b=SR/19ZHasdw8B6hHrkV1RIxZpjghFISPKDWL/374bqj2DvDLbAo0LWspbGZmEnts9pCyvtVA5qyp7B+xnjHSi+wC3+R7a1Lv5fZ8Qn29nRk+SNPlX30eVnyPw/eAslhfI20aCP6wLDX/woPXAsmhk9SYoncTGqiVR/P0G3Ckp8/NMsKTKqWY5EdpwxI/EhN86bYjTdhQLZ0AKIXROhYwRcYKnrdwE/YZJ8P7ugnv9Fzj+eMbcfZAq/+7WlNVeiXPBsbzsVmIh0d6mxzBUZ1dBxnjZqToam0e/uiQXuBzKvKAOiDGFeVXep/n4GgXlWHu0OHEMI7jS7CYpBB5W3Dbmg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1t5Qnl-0003SQ-PK for bug-gnu-emacs@gnu.org; Mon, 28 Oct 2024 10:33:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 Oct 2024 14:33:01 +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.173012592413196 (code B ref 68006); Mon, 28 Oct 2024 14:33:01 +0000 Original-Received: (at 68006) by debbugs.gnu.org; 28 Oct 2024 14:32:04 +0000 Original-Received: from localhost ([127.0.0.1]:54286 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t5Qmp-0003Ql-Uk for submit@debbugs.gnu.org; Mon, 28 Oct 2024 10:32:04 -0400 Original-Received: from ledu-giraud.fr ([51.159.28.247]:26384) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1t5Qmm-0003QK-PQ for 68006@debbugs.gnu.org; Mon, 28 Oct 2024 10:32:02 -0400 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=MYbwKHq7 pvfWGzJD+yxmjfoYOrt0GS7sUib51ySNDE8=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=9MLid+uxb+9LzM3cXMiba5AkkGtjeu JGBSMvCWkI9HVT2ewRW8YRclX3WaY5+/TeVCTDnn9iVmdCT3SINgAjDg== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=MYbwKHq7pvfWGzJD +yxmjfoYOrt0GS7sUib51ySNDE8=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=WRyK6TLnJvaXGlQ5reJwf++W4aikOmh9tLSsR8 DIyijeD6mzs/s0NteM9eMmYPZ6CCvlRrPaluwt6B90WG7Y3crx3NjmCvMhr5ZOA0B/gigC Wvm69sCXjrHUYlizGbDkhSzvbAdKbZMgBgMTnn6KSwCFfkMqjl/67u0SX78mo8QCmwi2/R Xp5dRupRYKx644KBVSVy3yPcivPPq6HiAxvY6wDh/GfQXBDASHB6CcNbsvZXQm8PglHFAB AkfBi2OBznF3uu8ig8hQGvUwdbziLy8hMPOK2MAGfWygW/Ddk9r/eQHq6/3rNR4VH39w0y CZRAcoi0mrWaKXMwpyVJxC5g== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id e37c67ee (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Mon, 28 Oct 2024 15:31:22 +0100 (CET) In-Reply-To: <867ca1h69p.fsf@gnu.org> (Eli Zaretskii's message of "Mon, 21 Oct 2024 17:36:50 +0300") 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:294428 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi Eli and Stefan, Here is a new version for my patch to add some user control on the image cache. This time, I have done some tests and benchmarks. Instead of trying to have a completely different cache, I'm using the current one but I had a condition to flush (or not) an image based on a user defined time to live (TTL) for an image. This TTL is a number of seconds since the image was last displayed. I have also tested it in image-mode with the second patch. I tested by browsing a directory with some rather large pictures in it (4000x3000 pixels, =E2=89=886MB for each file). I opened the first image in a 1640x10= 00 window (so each image is scaled) and did the following: - M-: (dotimes (i 10) (image-next-file 1)) ;; for cache warming - M-: (dotimes (i 10) (image-next-file -1)) ;; return to first image - M-: (benchmark-run 10 (dotimes (i 10) (image-next-file 1)) (dotimes (i 10) (image-next-file -1))) Here is the timings I get: - with master (ea685170063): (109.208767158 15 1.0938777159999997) - with this patch: (6.934307561 15 1.095243891) WDYT? --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-User-defined-time-to-live-for-image.patch >From cfa3858ab954fd8354d3b080975f2d679004f294 Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Mon, 28 Oct 2024 14:35:06 +0100 Subject: [PATCH 1/2] User defined time to live for image --- src/dispextern.h | 3 +++ src/image.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/dispextern.h b/src/dispextern.h index cc248a4472e..52887ce1687 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -3141,6 +3141,9 @@ reset_mouse_highlight (Mouse_HLInfo *hlinfo) in prepare_image_for_display. */ struct timespec timestamp; + /* Time to live after last displayed in seconds. */ + EMACS_INT ttl; + /* Pixmaps of the image. */ Emacs_Pixmap pixmap, mask; diff --git a/src/image.c b/src/image.c index 34936977a40..1343276b8c8 100644 --- a/src/image.c +++ b/src/image.c @@ -1744,6 +1744,7 @@ make_image (Lisp_Object spec, EMACS_UINT hash) { struct image *img = xzalloc (sizeof *img); Lisp_Object file = image_spec_value (spec, QCfile, NULL); + Lisp_Object ttl = image_spec_value (spec, QCttl, NULL); eassert (valid_image_p (spec)); img->dependencies = NILP (file) ? Qnil : list1 (file); @@ -1754,6 +1755,11 @@ make_image (Lisp_Object spec, EMACS_UINT hash) img->ascent = DEFAULT_IMAGE_ASCENT; img->hash = hash; img->corners[BOT_CORNER] = -1; /* Full image */ + if (! NILP (ttl) && FIXNUMP (ttl)) + img->ttl = XFIXNUM (ttl); + else + img->ttl = 0; + return img; } @@ -2258,11 +2264,13 @@ filter_image_spec (Lisp_Object spec) spec = XCDR (spec); /* Some animation-related data doesn't affect display, but - breaks the image cache. Filter those out. */ + breaks the image cache. Filter those out. Also filter out + the user's cache time to live. */ if (!(EQ (key, QCanimate_buffer) || EQ (key, QCanimate_tardiness) || EQ (key, QCanimate_position) - || EQ (key, QCanimate_multi_frame_data))) + || EQ (key, QCanimate_multi_frame_data) + || EQ (key, QCttl))) { out = Fcons (value, out); out = Fcons (key, out); @@ -2332,11 +2340,31 @@ clear_image_cache (struct frame *f, Lisp_Object filter) if (c && !f->inhibit_clear_image_cache) { ptrdiff_t i, nfreed = 0; + struct timespec now = current_timespec (); + struct timespec t, delay; /* Block input so that we won't be interrupted by a SIGIO while being in an inconsistent state. */ block_input (); + /* First, filter image cache based on image's time to live. */ + for (i = 0; i < c->used; ++i) + { + struct image *img = c->images[i]; + /* A negative TTL means that this image is cached forever. */ + if (img && img->ttl >= 0) + { + delay.tv_sec = img->ttl; + delay.tv_nsec = 0; + t = timespec_add(now, delay); + if (timespec_cmp (t, img->timestamp) > 0) + { + free_image (f, img); + ++nfreed; + } + } + } + if (!NILP (filter)) { /* Filter image cache. */ @@ -12979,6 +13007,7 @@ syms_of_image (void) DEFSYM (QCcolor_adjustment, ":color-adjustment"); DEFSYM (QCmask, ":mask"); DEFSYM (QCflip, ":flip"); + DEFSYM (QCttl, ":ttl"); /* Other symbols. */ DEFSYM (Qlaplace, "laplace"); -- 2.47.0 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Try-it-in-image-mode.patch >From ca5df9e0e7cc00eea1e7fc74d41b33c52aeddfab Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Mon, 28 Oct 2024 14:37:47 +0100 Subject: [PATCH 2/2] Try it in image-mode --- lisp/image-mode.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/image-mode.el b/lisp/image-mode.el index e75f6ea918f..ffc2697085e 100644 --- a/lisp/image-mode.el +++ b/lisp/image-mode.el @@ -949,12 +949,14 @@ image-toggle-display-image ;; default scaling based on font size. (setq image (if (not edges) (create-image file-or-data type data-p :scale 1 - :format (and filename data-p)) + :format (and filename data-p) + :ttl 30) (create-image file-or-data type data-p :scale 1 :max-width max-width :max-height max-height ;; Type hint. - :format (and filename data-p)))) + :format (and filename data-p) + :ttl 30))) ;; Handle `fit-window'. (when (and (eq image-transform-resize 'fit-window) @@ -964,8 +966,6 @@ 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) (setq image (image--update-properties image (image-transform-properties image))) (setq props `(display ,image -- 2.47.0 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--