unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Morgan Smith <Morgan.J.Smith@outlook.com>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 57367@debbugs.gnu.org
Subject: bug#57367: [PATCH V2] Speed up em-smart
Date: Tue, 06 Sep 2022 21:30:18 -0400	[thread overview]
Message-ID: <DM5PR03MB3163B313390CF7E1B6286E26C5419@DM5PR03MB3163.namprd03.prod.outlook.com> (raw)
In-Reply-To: <87ilm0x1ol.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 06 Sep 2022 12:00:26 +0200")

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


Hello,

I've attached my patch V2.

This restores some more of the original logic that I have now realized
was indeed necessary.  Again, this patch should not actually change
anything with respect to program logic, flow, or user experience.  In my
limited testing, it seems to act just as it did before (but
significantly more performant).


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Speed-up-em-smart.patch --]
[-- Type: text/x-patch, Size: 6297 bytes --]

From 9e5b3d44019d08e12f95e5cc06c2273e3030e1bb Mon Sep 17 00:00:00 2001
From: Morgan Smith <Morgan.J.Smith@outlook.com>
Date: Tue, 6 Sep 2022 21:18:51 -0400
Subject: [PATCH] Speed up em-smart

em-smart was forcibly re-displaying the screen upwards of 500 times
per screen of output.  This caused the eshell to feel quite slow when
the module was in use.  Everything seems to work just fine without any
redisplay stuff so I just tore it all out.

lisp/eshell/em-smart.el:

(eshell-smart-unload-hook): Remove `eshell-smart-scroll-windows'
instead of the now deleted `eshell-refresh-windows'

(eshell-smart-displayed, eshell-currently-handling-window,
eshell-refresh-windows, eshell-smart-redisplay): Delete

(eshell-smart-scroll-window): Rename to `eshell-smart-scroll-windows'
and add a bunch of logic originally from `eshell-refresh-windows'

(eshell-smart-initialize): Don't add a hook onto
`window-scroll-functions'.  Replace `eshell-refresh-windows' with
`eshell-smart-scroll-windows'

(eshell-smart-display-setup): Don't refresh windows

(eshell-smart-scroll): Add function.  Most of the logic is copied from
the now deleted `eshell-smart-redisplay'.
---
 lisp/eshell/em-smart.el | 81 ++++++++++++++---------------------------
 1 file changed, 28 insertions(+), 53 deletions(-)

diff --git a/lisp/eshell/em-smart.el b/lisp/eshell/em-smart.el
index 6768cee4c3..7763396a7d 100644
--- a/lisp/eshell/em-smart.el
+++ b/lisp/eshell/em-smart.el
@@ -96,7 +96,7 @@ it to get a real sense of how it works."
   (list
    (lambda ()
      (remove-hook 'window-configuration-change-hook
-                  'eshell-refresh-windows)))
+                  'eshell-smart-scroll-windows)))
   "A hook that gets run when `eshell-smart' is unloaded."
   :type 'hook
   :group 'eshell-smart)
@@ -159,9 +159,7 @@ The options are `begin', `after' or `end'."
 
 ;;; Internal Variables:
 
-(defvar eshell-smart-displayed nil)
 (defvar eshell-smart-command-done nil)
-(defvar eshell-currently-handling-window nil)
 
 ;;; Functions:
 
@@ -174,10 +172,9 @@ The options are `begin', `after' or `end'."
     (setq-local eshell-scroll-to-bottom-on-input nil)
     (setq-local eshell-scroll-show-maximum-output t)
 
-    (add-hook 'window-scroll-functions 'eshell-smart-scroll-window nil t)
-    (add-hook 'window-configuration-change-hook 'eshell-refresh-windows)
+    (add-hook 'eshell-output-filter-functions 'eshell-smart-scroll-windows nil t)
 
-    (add-hook 'eshell-output-filter-functions 'eshell-refresh-windows t t)
+    (add-hook 'window-configuration-change-hook 'eshell-smart-scroll-windows nil t)
 
     (add-hook 'after-change-functions 'eshell-disable-after-change nil t)
 
@@ -193,29 +190,14 @@ The options are `begin', `after' or `end'."
       (add-hook 'eshell-post-command-hook
 		'eshell-smart-maybe-jump-to-end nil t))))
 
-;; This is called by window-scroll-functions with two arguments.
-(defun eshell-smart-scroll-window (wind _start)
-  "Scroll the given Eshell window WIND accordingly."
-  (unless eshell-currently-handling-window
-    (let ((inhibit-point-motion-hooks t)
-	  (eshell-currently-handling-window t))
-      (with-selected-window wind
-	(eshell-smart-redisplay)))))
-
-(defun eshell-refresh-windows (&optional frame)
-  "Refresh all visible Eshell buffers."
-  (let (affected)
-    (walk-windows
-     (lambda (wind)
-       (with-current-buffer (window-buffer wind)
-         (if eshell-mode
-             (let (window-scroll-functions) ;;FIXME: Why?
-               (eshell-smart-scroll-window wind (window-start))
-               (setq affected t)))))
-     0 frame)
-    (if affected
-	(let (window-scroll-functions) ;;FIXME: Why?
-	  (eshell-redisplay)))))
+(defun eshell-smart-scroll-windows ()
+  "Scroll all eshell windows to display as much output as possible, smartly."
+  (walk-windows
+   (lambda (wind)
+     (with-current-buffer (window-buffer wind)
+       (if eshell-mode
+           (eshell-smart-scroll wind))))
+   0 t))
 
 (defun eshell-smart-display-setup ()
   "Set the point to somewhere in the beginning of the last command."
@@ -232,8 +214,7 @@ The options are `begin', `after' or `end'."
    (t
     (error "Invalid value for `eshell-where-to-jump'")))
   (setq eshell-smart-command-done nil)
-  (add-hook 'pre-command-hook 'eshell-smart-display-move nil t)
-  (eshell-refresh-windows))
+  (add-hook 'pre-command-hook 'eshell-smart-display-move nil t))
 
 ;; Called from after-change-functions with 3 arguments.
 (defun eshell-disable-after-change (_b _e _l)
@@ -255,28 +236,22 @@ and the end of the buffer are still visible."
     (goto-char (point-max))
     (remove-hook 'pre-command-hook 'eshell-smart-display-move t)))
 
-(defun eshell-smart-redisplay ()
-  "Display as much output as possible, smartly."
-  (if (eobp)
-      (save-excursion
-	(recenter -1)
-	;; trigger the redisplay now, so that we catch any attempted
-	;; point motion; this is to cover for a redisplay bug
-	(eshell-redisplay))
-    (let ((top-point (point)))
-      (and (memq 'eshell-smart-display-move pre-command-hook)
-	   (>= (point) eshell-last-input-start)
-	   (< (point) eshell-last-input-end)
-	   (set-window-start (selected-window)
-			     (line-beginning-position) t))
-      (if (pos-visible-in-window-p (point-max))
-	  (save-excursion
-	    (goto-char (point-max))
-	    (recenter -1)
-	    (unless (pos-visible-in-window-p top-point)
-	      (goto-char top-point)
-	      (set-window-start (selected-window)
-				(line-beginning-position) t)))))))
+(defun eshell-smart-scroll (window)
+  "Scroll WINDOW to display as much output as possible, smartly."
+  (let ((top-point (point)))
+    (and (memq 'eshell-smart-display-move pre-command-hook)
+         (>= (point) eshell-last-input-start)
+         (< (point) eshell-last-input-end)
+         (set-window-start window
+                           (line-beginning-position) t))
+    (if (pos-visible-in-window-p (point-max) window)
+        (save-excursion
+          (goto-char (point-max))
+          (recenter -1)
+          (unless (pos-visible-in-window-p top-point window)
+            (goto-char top-point)
+            (set-window-start window
+                              (line-beginning-position) t))))))
 
 (defun eshell-smart-goto-end ()
   "Like `end-of-buffer', but do not push a mark."
-- 
2.37.2


[-- Attachment #3: Type: text/plain, Size: 205 bytes --]


Lars Ingebrigtsen <larsi@gnus.org> writes:

> (Please keep the debbugs address in the CCs -- otherwise it won't reach
> the bug tracker.)

Sorry, still trying to get the hang of gnus :P


Thanks,

Morgan

  reply	other threads:[~2022-09-07  1:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-23 20:06 bug#57367: [PATCH] Speed up em-smart Morgan Smith
2022-09-04 21:56 ` Lars Ingebrigtsen
2022-09-05 19:01   ` Jim Porter
2022-09-05 21:48     ` Morgan Smith
2022-09-05 21:51       ` Lars Ingebrigtsen
     [not found]         ` <DM5PR03MB31639CBC75F62622AC4E70ABC57E9@DM5PR03MB3163.namprd03.prod.outlook.com>
2022-09-06 10:00           ` Lars Ingebrigtsen
2022-09-07  1:30             ` Morgan Smith [this message]
2022-09-07 12:55               ` bug#57367: [PATCH V2] " Lars Ingebrigtsen
2022-09-09  4:36               ` Jim Porter
2023-09-06 22:46                 ` bug#57367: [PATCH] " Stefan Kangas
2023-10-18 15:46                   ` bug#57367: [PATCH v3] " Morgan Smith
2023-10-28 22:47                     ` Jim Porter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DM5PR03MB3163B313390CF7E1B6286E26C5419@DM5PR03MB3163.namprd03.prod.outlook.com \
    --to=morgan.j.smith@outlook.com \
    --cc=57367@debbugs.gnu.org \
    --cc=larsi@gnus.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).