Skip to content

Commit 4449f16

Browse files
committed
Optimize diff-hl--update
This adds optimizations to the buffer traversal and overlay application logic: - Cache the boolean state of (or changes ref-changes) into a local variable 'has-changes' outside the loop to prevent the Lisp interpreter from recalculating it for all active buffers. - Bind inhibit-redisplay to t during the resolution callback to prevent the display engine from rendering intermediate UI states during asynchronous overlay updates. - Conditionally execute diff-hl--update-overlays only when 'changes' or 'ref-changes' are non-nil, avoiding unnecessary function calls.
1 parent 81b7628 commit 4449f16

1 file changed

Lines changed: 12 additions & 11 deletions

File tree

diff-hl.el

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -744,20 +744,21 @@ Return a list of line overlays used."
744744
(let ((ref-changes (diff-hl-adjust-changes ref-changes changes))
745745
(base (diff-hl--target-buffer orig)))
746746
(dolist (buf (buffer-list))
747-
(when (and (buffer-live-p buf)
748-
(eq (diff-hl--target-buffer buf) base)
747+
(when (and (eq (diff-hl--target-buffer buf) base)
749748
(buffer-local-value 'diff-hl-mode buf))
750749
(with-current-buffer buf
750+
(diff-hl-remove-overlays)
751751
(let (reuse)
752-
(diff-hl-remove-overlays)
753-
(let ((diff-hl-highlight-function
754-
diff-hl-highlight-reference-function)
755-
(diff-hl-fringe-face-function
756-
diff-hl-fringe-reference-face-function))
757-
(setq reuse (diff-hl--update-overlays ref-changes nil)))
758-
(diff-hl--update-overlays changes reuse)
759-
(when (not (or changes ref-changes))
760-
(diff-hl--autohide-margin))))))))))))))
752+
(when ref-changes
753+
(let ((diff-hl-highlight-function
754+
diff-hl-highlight-reference-function)
755+
(diff-hl-fringe-face-function
756+
diff-hl-fringe-reference-face-function))
757+
(setq reuse (diff-hl--update-overlays ref-changes nil))))
758+
(when changes
759+
(diff-hl--update-overlays changes reuse)))
760+
(unless (or changes ref-changes)
761+
(diff-hl--autohide-margin)))))))))))))
761762

762763
(defun diff-hl--resolve (value-or-buffer cb)
763764
(if (listp value-or-buffer)

0 commit comments

Comments
 (0)