perf(tabs): rate limit centaur-tabs-buffer-update-groups
`centaur-tabs-buffer-update-groups` walks every buffer to determine the group it belongs to. This function can be called execessively (upwards of 1,000 times per second in certain conditions), as it is called on every redisplay (it is indirectly attached to `tab-line-format`). This rate limits its calls to about 10 per second. Close: #7792 Ref: ema2159/centaur-tabs#222
This commit is contained in:
parent
1fbb78e92b
commit
8d4e355af6
1 changed files with 23 additions and 1 deletions
|
@ -1,5 +1,14 @@
|
||||||
;;; ui/tabs/config.el -*- lexical-binding: t; -*-
|
;;; ui/tabs/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(defcustom +tabs-buffer-update-groups-delay 0.1
|
||||||
|
"Minimum wait time (in seconds) before tab groups are recalculated."
|
||||||
|
:type 'float
|
||||||
|
:group 'doom)
|
||||||
|
|
||||||
|
|
||||||
|
;;
|
||||||
|
;;; Packages
|
||||||
|
|
||||||
(use-package! centaur-tabs
|
(use-package! centaur-tabs
|
||||||
:hook (doom-first-file . centaur-tabs-mode)
|
:hook (doom-first-file . centaur-tabs-mode)
|
||||||
:init
|
:init
|
||||||
|
@ -20,7 +29,20 @@
|
||||||
(defun +tabs-disable-centaur-tabs-mode-maybe-h ()
|
(defun +tabs-disable-centaur-tabs-mode-maybe-h ()
|
||||||
"Disable `centaur-tabs-mode' in current buffer."
|
"Disable `centaur-tabs-mode' in current buffer."
|
||||||
(when (centaur-tabs-mode-on-p)
|
(when (centaur-tabs-mode-on-p)
|
||||||
(centaur-tabs-local-mode)))))
|
(centaur-tabs-local-mode))))
|
||||||
|
|
||||||
|
;; HACK: `centaur-tabs-buffer-update-groups' is both expensive and called too
|
||||||
|
;; frequently. There really is no reason to call it more than 10 times per
|
||||||
|
;; second, as buffers rarely change groups more frequently than that.
|
||||||
|
(let ((time (float-time)))
|
||||||
|
(defadvice! +tabs--rate-limit-buffer-update-groups-a (fn)
|
||||||
|
:around #'centaur-tabs-buffer-update-groups
|
||||||
|
(let ((now (float-time)))
|
||||||
|
(if-let ((buf (and (< now (+ time +tabs-buffer-update-groups-delay))
|
||||||
|
(assq (current-buffer) centaur-tabs--buffers))))
|
||||||
|
(car (nth 2 buf))
|
||||||
|
(setq time now)
|
||||||
|
(funcall fn))))))
|
||||||
|
|
||||||
|
|
||||||
;; TODO tab-bar-mode (emacs 27)
|
;; TODO tab-bar-mode (emacs 27)
|
||||||
|
|
Loading…
Reference in a new issue