unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* WIP/RFP: lazy body insertion for notmuch-show mode
@ 2022-06-05 17:08 David Bremner
  2022-06-05 17:08 ` [PATCH 1/3] perf-test/emacs: test showing a longish thread David Bremner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Bremner @ 2022-06-05 17:08 UTC (permalink / raw)
  To: notmuch

Many people have observed that notmuch-show is slow to render large
threads. This is pretty annoying when most of the thread is off
screen. The usual trick of working asynchronously doesn't seem
hopeful, since most of the work is in emacs proper, not externally.
This series attempts to reduce the amount of time before emacs is
responsive again by deferring the rendering of messages below a
certain depth in the tree until the user manually triggers it, via a
button.

It isn't clear that depth is the best heuristic, but this seems like
an improvement on the status quo. Other heuristics could be added
later. I thought about some kind of "expose events" triggering the
rendering but I'm not sure that's better (and it seems harder). With
this approach the user can skip a few levels down the tree to render
the message they are interested in.

I learned while writing this that "text-buttons" might be faster. I'm
not sure my test thread of 264 messages is long enough to see the
difference. It would be helpful if people could test expanding message
bodies and see if there is an annoying lag. You will need to customize
the variable notmuch-show-depth-limit to test.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] perf-test/emacs: test showing a longish thread
  2022-06-05 17:08 WIP/RFP: lazy body insertion for notmuch-show mode David Bremner
@ 2022-06-05 17:08 ` David Bremner
  2022-06-05 17:08 ` [PATCH 2/3] emacs/show: optionally insert bodies lazily David Bremner
  2022-06-05 17:08 ` [PATCH 3/3] perf-test/emacs: lazily insert message bodies with notmuch-show David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2022-06-05 17:08 UTC (permalink / raw)
  To: notmuch

This particular thread takes about 100 times longer to display in
emacs than on the command line.
---
 performance-test/T06-emacs.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/performance-test/T06-emacs.sh b/performance-test/T06-emacs.sh
index 66f0be58..ce04ca17 100755
--- a/performance-test/T06-emacs.sh
+++ b/performance-test/T06-emacs.sh
@@ -18,4 +18,7 @@ time_emacs "tag messages" \
    (notmuch-tag msg (list \"+test\"))
    (notmuch-tag msg (list \"-test\"))))"
 
+time_emacs "show thread" \
+	   '(notmuch-show "thread:{id:tip-4f8219875a0dad2cfad9e93a3fafcd9626db98d2@git.kernel.org}")'
+
 time_done
-- 
2.35.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] emacs/show: optionally insert bodies lazily
  2022-06-05 17:08 WIP/RFP: lazy body insertion for notmuch-show mode David Bremner
  2022-06-05 17:08 ` [PATCH 1/3] perf-test/emacs: test showing a longish thread David Bremner
@ 2022-06-05 17:08 ` David Bremner
  2022-06-05 17:08 ` [PATCH 3/3] perf-test/emacs: lazily insert message bodies with notmuch-show David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2022-06-05 17:08 UTC (permalink / raw)
  To: notmuch

Intially control lazy insertion by a depth limit.
---
 emacs/notmuch-show.el | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index 203ca7f0..55c4e274 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -111,6 +111,12 @@ displayed."
 		 (function :tag "Function"))
   :group 'notmuch-show)
 
+(defcustom notmuch-show-depth-limit nil
+  "Depth beyond which message bodies are inserted lazily"
+    :type '(choice (const :tag "No limit" nil)
+                   (number :tag "Limit" 10))
+    :group 'notmuch-show)
+
 (defcustom notmuch-show-relative-dates t
   "Display relative dates in the message summary line."
   :type 'boolean
@@ -1065,13 +1071,35 @@ is t, hide the part initially and show the button."
 	(notmuch-show-toggle-part-invisibility button)))
     (notmuch-show-record-part-information part beg (point))))
 
+(defun notmuch-show--insert-body-internal (msg body depth)
+  (mapc (lambda (part) (notmuch-show-insert-bodypart msg part depth)) body))
+
+(defun notmuch-show--insert-body-button (msg body depth)
+  (insert-button
+   "[body]"
+   :type 'notmuch-button-type
+   'action (lambda (button)
+	     (save-excursion
+	       (let* ((inhibit-read-only t)
+		     (start (button-start button))
+		     (end (button-end button))
+		     (marker (copy-marker (1+ end))))
+		 (delete-region start end)
+		 (notmuch-show--insert-body-internal msg body depth)
+		 (when notmuch-show-indent-content
+		   (indent-rigidly start marker
+				   (* notmuch-show-indent-messages-width depth))))))))
+
 (defun notmuch-show-insert-body (msg body depth)
   "Insert the body BODY at depth DEPTH in the current thread."
   ;; Register all content IDs for this message.  According to RFC
   ;; 2392, content IDs are *global*, but it's okay if an MUA treats
   ;; them as only global within a message.
   (notmuch-show--register-cids msg (car body))
-  (mapc (lambda (part) (notmuch-show-insert-bodypart msg part depth)) body))
+  (if (and notmuch-show-depth-limit
+	   (> depth notmuch-show-depth-limit))
+      (notmuch-show--insert-body-button msg body depth)
+    (notmuch-show--insert-body-internal msg body depth)))
 
 (defun notmuch-show-make-symbol (type)
   (make-symbol (concat "notmuch-show-" type)))
-- 
2.35.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] perf-test/emacs: lazily insert message bodies with notmuch-show
  2022-06-05 17:08 WIP/RFP: lazy body insertion for notmuch-show mode David Bremner
  2022-06-05 17:08 ` [PATCH 1/3] perf-test/emacs: test showing a longish thread David Bremner
  2022-06-05 17:08 ` [PATCH 2/3] emacs/show: optionally insert bodies lazily David Bremner
@ 2022-06-05 17:08 ` David Bremner
  2 siblings, 0 replies; 4+ messages in thread
From: David Bremner @ 2022-06-05 17:08 UTC (permalink / raw)
  To: notmuch

As expected / hoped, this is much faster for large threads than
actually inserting the bodies.
---
 performance-test/T06-emacs.sh | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/performance-test/T06-emacs.sh b/performance-test/T06-emacs.sh
index ce04ca17..7f6fdfbe 100755
--- a/performance-test/T06-emacs.sh
+++ b/performance-test/T06-emacs.sh
@@ -21,4 +21,8 @@ time_emacs "tag messages" \
 time_emacs "show thread" \
 	   '(notmuch-show "thread:{id:tip-4f8219875a0dad2cfad9e93a3fafcd9626db98d2@git.kernel.org}")'
 
+time_emacs "lazy show" \
+	   '(let ((notmuch-show-depth-limit 0))
+		(notmuch-show "thread:{id:tip-4f8219875a0dad2cfad9e93a3fafcd9626db98d2@git.kernel.org}"))'
+
 time_done
-- 
2.35.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-06-05 17:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-05 17:08 WIP/RFP: lazy body insertion for notmuch-show mode David Bremner
2022-06-05 17:08 ` [PATCH 1/3] perf-test/emacs: test showing a longish thread David Bremner
2022-06-05 17:08 ` [PATCH 2/3] emacs/show: optionally insert bodies lazily David Bremner
2022-06-05 17:08 ` [PATCH 3/3] perf-test/emacs: lazily insert message bodies with notmuch-show David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.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).