diff --git a/modules/ui/vc-gutter/config.el b/modules/ui/vc-gutter/config.el index 8a5c86950..2d27dad4d 100644 --- a/modules/ui/vc-gutter/config.el +++ b/modules/ui/vc-gutter/config.el @@ -81,19 +81,14 @@ Respects `diff-hl-disable-on-remote'." (setq diff-hl-global-modes '(not image-mode pdf-view-mode)) ;; PERF: A slightly faster algorithm for diffing. (setq vc-git-diff-switches '("--histogram")) - ;; PERF: Slightly more conservative delay before updating the diff - (setq diff-hl-flydiff-delay 0.5) ; default: 0.3 + ;; PERF: Slightly more conservative delay before updating the diff. More so on + ;; MacOS where async process management is slower. + (setq diff-hl-flydiff-delay (if (featurep :system 'macos) 1.0 0.5)) ; default: 0.3 ;; PERF: don't block Emacs when updating vc gutter - (setq diff-hl-update-async t) + (setq diff-hl-update-async (or (> emacs-major-version 30) 'thread)) ;; UX: get realtime feedback in diffs after staging/unstaging hunks. (setq diff-hl-show-staged-changes nil) - ;; PERF: MacOS appears to struggle with async processes, causing Emacs to slow - ;; to a crawl/freeze. Possibly because diff-hl fires off too many git - ;; processes, so we tone it down there. - (when (featurep :system 'macos) - (setq diff-hl-update-async nil - diff-hl-flydiff-delay 2.0)) ;; UX: Update diffs when it makes sense too, without being too slow (when (modulep! :editor evil) @@ -142,7 +137,7 @@ Respects `diff-hl-disable-on-remote'." (shrink-window-if-larger-than-buffer))) (apply fn args))) - ;; UX: Don't delete the current hunk's indicators while we're editing + ;; UX: Update diff-hl immediately upon exiting insert mode. (when (modulep! :editor evil) (add-hook! 'diff-hl-flydiff-mode-hook (defun +vc-gutter-init-flydiff-mode-h () @@ -157,58 +152,4 @@ Respects `diff-hl-disable-on-remote'." :around #'diff-hl-revert-hunk (let ((pt (point))) (prog1 (apply fn args) - (goto-char pt)))) - - ;; FIX: `global-diff-hl-mode' enables `diff-hl-mode' *everywhere*, which calls - ;; `diff-hl-update'. If `diff-hl-update-async' is non-nil, this means a new - ;; thread is spawned for *every* buffer, whether they're visible or not. Not - ;; only can this slow a lot down, but `kill-buffer' will silently refuse to - ;; kill buffers with a thread associated with it. Chaos ensues (see #7991 - ;; and #7954). - ;; REVIEW: Report this upstream. - (defun +vc-gutter--kill-thread (&optional block?) - (when-let ((th +vc-gutter--diff-hl-thread)) - (when (thread-live-p th) - (thread-signal th 'quit nil) - (when block? - (condition-case _ - (thread-join th) - ((quit error) nil)))))) - - (defvar-local +vc-gutter--diff-hl-thread nil) - (defadvice! +vc-gutter--debounce-threads-a (&rest _) - :override #'diff-hl-update - (unless (or non-essential - delay-mode-hooks - (null (buffer-file-name (buffer-base-buffer))) - (null (get-buffer-window (current-buffer)))) - (setq diff-hl-timer nil) - (if (and diff-hl-update-async - (not - (run-hook-with-args-until-success 'diff-hl-async-inhibit-functions - default-directory))) - (progn - (+vc-gutter--kill-thread) - (setq +vc-gutter--diff-hl-thread - (make-thread (lambda () - (unwind-protect - (diff-hl--update-safe) - (setq +vc-gutter--diff-hl-thread nil))) - "diff-hl--update-safe"))) - (diff-hl--update)) - t)) - - ;; (defadvice! +vc-gutter--only-tick-on-success-a (&rest _) - ;; :override #'diff-hl-update-once - ;; (unless (equal diff-hl--modified-tick (buffer-chars-modified-tick)) - ;; (when (diff-hl-update) - ;; (setq diff-hl--modified-tick (buffer-chars-modified-tick))))) - - ;; HACK: This advice won't work in *all* cases (it's a C function, and any - ;; calls to it from C won't trigger advice), but the thread issues above are - ;; triggered from Elisp's buffer API (from what I can tell). - (defadvice! +vc-gutter--kill-diff-hl-thread-a (&optional buf) - :before #'kill-buffer - (when-let ((buf (ignore-errors (window-normalize-buffer buf)))) - (with-current-buffer buf - (+vc-gutter--kill-thread t))))) + (goto-char pt))))) diff --git a/modules/ui/vc-gutter/packages.el b/modules/ui/vc-gutter/packages.el index 549af11e2..1d1e2424f 100644 --- a/modules/ui/vc-gutter/packages.el +++ b/modules/ui/vc-gutter/packages.el @@ -1,4 +1,4 @@ ;; -*- no-byte-compile: t; -*- ;;; ui/vc-gutter/packages.el -(package! diff-hl :pin "0fe1bc0fd8716e8521f49fdbeae68da64ea4772f") +(package! diff-hl :pin "e79aa49ad3cbbe85379cf6646db3aaacd3b04708")