all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#71961: [PATCH] Improve tab-line-tabs-fixed-window-buffers performance
@ 2024-07-05 14:50 Eval Exec
  2024-07-07 20:32 ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 1 reply; 2+ messages in thread
From: Eval Exec @ 2024-07-05 14:50 UTC (permalink / raw)
  To: 71961

[-- Attachment #1: Type: text/plain, Size: 748 bytes --]

Hello,
After noticing severe lag when `buffer-list` exceeds 1000 buffers,
particularly
with `tab-line-switch-to-prev-tab` and `tab-line-switch-to-next-tab`,
a profiler
revealed that the sorting operation in
`tab-line-tabs-fixed-window-buffers` heavily
relies on the `seq-position` function. This reliance significantly
impacts performance.
To address this, I have proposed a patch to optimize the buffer
sorting mechanism within
`tab-line-tabs-fixed-window-buffers`. The solution involves replacing
the inefficient
`seq-position` calls with a hash table to cache buffer positions,
which markedly
enhances performance when handling large buffer lists.

This is my first attempt at hacking Emacs. Do you have any suggestions
on this idea?

Thank you

[-- Attachment #2: 0001-Improve-tab-line-tabs-fixed-window-buffers-performan.patch --]
[-- Type: text/x-patch, Size: 1555 bytes --]

From a378d7bec23bc0b3ec14ef564bb215a052be881e Mon Sep 17 00:00:00 2001
From: Eval EXEC <execvy@gmail.com>
Date: Fri, 5 Jul 2024 22:44:40 +0800
Subject: [PATCH] Improve tab-line-tabs-fixed-window-buffers performance

* lisp/tab-line.el (tab-line-tabs-fixed-window-buffers): Improve sorting performance by hashtable.
---
 lisp/tab-line.el | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index 1d14fda9825..e4908c61542 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -555,10 +555,14 @@ This means that switching to a buffer previously shown in the same
 window will keep the same order of tabs that was before switching.
 And newly displayed buffers are added to the end of the tab line."
   (let* ((old-buffers (window-parameter nil 'tab-line-buffers))
+         (buffer-positions (let ((index-table (make-hash-table :test 'eq)))
+                             (seq-do-indexed
+                              (lambda (buf idx) (puthash buf idx index-table))
+                              old-buffers)
+                             index-table))
          (new-buffers (sort (tab-line-tabs-window-buffers)
                             :key (lambda (buffer)
-                                   (or (seq-position old-buffers buffer)
-                                       most-positive-fixnum)))))
+                                   (gethash buffer buffer-positions most-positive-fixnum)))))
     (set-window-parameter nil 'tab-line-buffers new-buffers)
     new-buffers))
 
-- 
2.44.1


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

* bug#71961: [PATCH] Improve tab-line-tabs-fixed-window-buffers performance
  2024-07-05 14:50 bug#71961: [PATCH] Improve tab-line-tabs-fixed-window-buffers performance Eval Exec
@ 2024-07-07 20:32 ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors
  0 siblings, 0 replies; 2+ messages in thread
From: Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors @ 2024-07-07 20:32 UTC (permalink / raw)
  To: Eval Exec; +Cc: 71961, Juri Linkov

Eval Exec <execvy@gmail.com> writes:

> Hello,
> After noticing severe lag when `buffer-list` exceeds 1000 buffers,

1000?

> particularly
> with `tab-line-switch-to-prev-tab` and `tab-line-switch-to-next-tab`,
> a profiler
> revealed that the sorting operation in
> `tab-line-tabs-fixed-window-buffers` heavily
> relies on the `seq-position` function. This reliance significantly
> impacts performance.
> To address this, I have proposed a patch to optimize the buffer
> sorting mechanism within
> `tab-line-tabs-fixed-window-buffers`. The solution involves replacing
> the inefficient
> `seq-position` calls with a hash table to cache buffer positions,
> which markedly
> enhances performance when handling large buffer lists.
>
> This is my first attempt at hacking Emacs. Do you have any suggestions
> on this idea?

Adding Juri to this bug report

>
> Thank you
>
> [2. text/x-patch; 0001-Improve-tab-line-tabs-fixed-window-buffers-performan.patch]...





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

end of thread, other threads:[~2024-07-07 20:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-05 14:50 bug#71961: [PATCH] Improve tab-line-tabs-fixed-window-buffers performance Eval Exec
2024-07-07 20:32 ` Jeremy Bryant via Bug reports for GNU Emacs, the Swiss army knife of text editors

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.