emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 23d2e7d: image-dired: Increase number of asynch thumbnail generat


From: Stefan Kangas
Subject: master 23d2e7d: image-dired: Increase number of asynch thumbnail generation jobs
Date: Tue, 26 Oct 2021 19:54:31 -0400 (EDT)

branch: master
commit 23d2e7d112dd1a06b4392185cb78a03a96baf34c
Author: Stefan Kangas <stefan@marxist.se>
Commit: Stefan Kangas <stefan@marxist.se>

    image-dired: Increase number of asynch thumbnail generation jobs
    
    * lisp/image-dired.el (image-dired-queue-active-limit): Increase the
    number of asynchronous thumbnail generation jobs to a maximum of 4 or
    processor count divided by 2.  This makes thumbnail generation around
    30 % faster when benchmarking this on my machine (8 cores/4 jobs).
    
    (image-dired-debug): New defvar.
    (image-dired-debug-message): New defun.
    
    (image-dired--generate-thumbs-start): New defvar.
    (image-dired-create-thumb-1, image-dired-display-thumbs): Display time
    spent on thumbnail generation if 'image-dired-debug' is non-nil.
---
 lisp/image-dired.el | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index d73dbdb..4ce61ea 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -576,6 +576,14 @@ If there are more files than this in a selected directory, 
the
   :type 'integer
   :version "29.1")
 
+(defvar image-dired-debug nil
+  "Non-nil means enable debug messages.")
+
+(defun image-dired-debug-message (&rest args)
+  "Display debug message ARGS when `image-dired-debug' is non-nil."
+  (when image-dired-debug
+    (apply #'message args)))
+
 (defmacro image-dired--with-db-file (&rest body)
   "Run BODY in a temp buffer containing `image-dired-db-file'.
 Return the last form in BODY."
@@ -704,6 +712,9 @@ DIMENSION should be either the symbol `width' or `height'."
         (width image-dired-thumb-width)
         (height image-dired-thumb-height)))))
 
+(defvar image-dired--generate-thumbs-start nil
+  "Time when `display-thumbs' was called.")
+
 (defvar image-dired-queue nil
   "List of items in the queue.
 Each item has the form (ORIGINAL-FILE TARGET-FILE).")
@@ -711,9 +722,12 @@ Each item has the form (ORIGINAL-FILE TARGET-FILE).")
 (defvar image-dired-queue-active-jobs 0
   "Number of active jobs in `image-dired-queue'.")
 
-(defvar image-dired-queue-active-limit 2
+(defvar image-dired-queue-active-limit (min 4 (max 2 (/ (num-processors) 2)))
   "Maximum number of concurrent jobs permitted for generating images.
-Increase at own risk.")
+Increase at own risk.  If you want to experiment with this,
+consider setting `image-dired-debug' to a non-nil value to see
+the time spent on generating thumbnails.  Run `image-clear-cache'
+and remove the cached thumbnail files between each trial run.")
 
 (defvar image-dired-tag-history nil "Variable holding the tag history.")
 
@@ -823,6 +837,12 @@ Increase at own risk.")
             ;; Trigger next in queue once a thumbnail has been created
             (cl-decf image-dired-queue-active-jobs)
             (image-dired-thumb-queue-run)
+            (when (= image-dired-queue-active-jobs 0)
+              (image-dired-debug-message
+               (format-time-string
+                "Generated thumbnails in %s.%3N seconds"
+                (time-subtract (current-time)
+                               image-dired--generate-thumbs-start))))
             (if (not (and (eq (process-status process) 'exit)
                           (zerop (process-exit-status process))))
                 (message "Thumb could not be created for %s: %s"
@@ -1076,6 +1096,7 @@ used or not.  If non-nil, use `display-buffer' instead of
 `image-dired-previous-line-and-display' where we do not want the
 thumbnail buffer to be selected."
   (interactive "P")
+  (setq image-dired--generate-thumbs-start  (current-time))
   (let ((buf (image-dired-create-thumbnail-buffer))
         thumb-name files dired-buf)
     (if arg



reply via email to

[Prev in Thread] Current Thread [Next in Thread]