From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Morgan Smith Newsgroups: gmane.emacs.bugs Subject: bug#57367: [PATCH v3] Speed up em-smart Date: Wed, 18 Oct 2023 11:46:57 -0400 Message-ID: References: <87r10q6byc.fsf@gnus.org> <9257e0e5-232e-7e20-f4d1-385066c4337e@gmail.com> <87bkrtxzfj.fsf@gnus.org> <87ilm0x1ol.fsf@gnus.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="23492"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Jim Porter , Lars Ingebrigtsen , 57367@debbugs.gnu.org To: Stefan Kangas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Oct 18 17:48:03 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qt8mB-0005wP-2z for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 18 Oct 2023 17:48:03 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qt8ln-0006qk-Sv; Wed, 18 Oct 2023 11:47:40 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qt8ll-0006pL-7z for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 11:47:37 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qt8ll-0005Rn-00 for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 11:47:37 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qt8mB-00052G-12 for bug-gnu-emacs@gnu.org; Wed, 18 Oct 2023 11:48:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Morgan Smith Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Oct 2023 15:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 57367 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: moreinfo patch Original-Received: via spool by 57367-submit@debbugs.gnu.org id=B57367.169764405719252 (code B ref 57367); Wed, 18 Oct 2023 15:48:02 +0000 Original-Received: (at 57367) by debbugs.gnu.org; 18 Oct 2023 15:47:37 +0000 Original-Received: from localhost ([127.0.0.1]:34505 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qt8lk-00050R-JH for submit@debbugs.gnu.org; Wed, 18 Oct 2023 11:47:37 -0400 Original-Received: from mail-bn7nam10olkn2033.outbound.protection.outlook.com ([40.92.40.33]:55086 helo=NAM10-BN7-obe.outbound.protection.outlook.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qt8lj-00050A-1M for 57367@debbugs.gnu.org; Wed, 18 Oct 2023 11:47:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=grqK8gfCVt+3OH7ZJxHet94XrsMMs8am7ZYHDUd8Haplhmz4TzQynamPlBiN1mpMyhBhCnDJ7zVoRAICi8HKk6kP0g8yuWwlIRRJHZBgkTOZ7d2fzmkFjhBvFfSd303jek8/g0DMmrQxY9UTk7QFsVCjOb7GUzn4Pg5lIBRJ5sNcDLCwZmNmXXgYZqA2xp7i6P82ZKG7z7FBL8wYWFQyZ40l5lNuHIh+dCjCZ0UIMDUldWyabg0XIB4Y3YhplqC44FbjX4wRIEk0PjWvwuNYpyPtHdNWcxjCkfSEHCiVa7SDwQjBpftGDsY0mdQXphXMUkm8Loc7yzgeQMxwwFBSMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1wDyXf5KCysXiLl2teTEqxTSy6YxRXFNlipB7EV9Fkk=; b=byjQRUIpFmhURVuVejAy+L1pkvMqXwZNKW0TJiXOUT2IgTDilLHWjqXQ+3y1rFJGs1K9P43hrMPiuUns/7g8EYz91GwIU9Dk2raUREbU8LNQ4om/Tjj2QPGLu2u/jkUK3SvrAwlcTIRJAgwNecZWB87x5hVqUoaVgS3y61trx4BaLjygefmG//iDBv0XXJ8gBuqzKaynO9CN5FrFELW1LHIvdTJmVqJDIXUg5hZiB7eZhRQ+FrmDz53/l/yUd7QFg84drxkIeRG6PxV0I/HsKvY+sox5jETQKfzmN36HrxwKlB5rzlHmHOH4uy4fb5Oz0IKyHOjCW4rL5O10qWtsHw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1wDyXf5KCysXiLl2teTEqxTSy6YxRXFNlipB7EV9Fkk=; b=Xd30eFeft85XGWUPUwUZbanP9FhvsSthfeiC73geOPaO4Ir3xQJZYPaoU4tou+fTPpG9XGTPCtT+FKOHuzL6MT4HO9Ot4DMGcOQ6R/4QDXiIgWJNHMdHdmITdtk8J6Em0dDRZSYQSl3h3z1/Tn17C4ve7cBO51FErNh7gPB6QfaBvHDlTkK4fpn31d4cjlK0L+BmzGzNJ5BvC/3FV8+Bdm1izSdtZprXTjkLRRDgtGQ3DPDJ7KaFLQFuqTMoaTAnfT/bDVzEMNeAraRg+OkqFg0OcAnr2pMclJ2cJHh7RcpnUf4mQzNvDGOrZcBjvaYonUCO7pZ1lu4UQX8wst1agg== Original-Received: from DM5PR03MB3163.namprd03.prod.outlook.com (2603:10b6:4:40::24) by CH2PR03MB5350.namprd03.prod.outlook.com (2603:10b6:610:99::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.7; Wed, 18 Oct 2023 15:47:02 +0000 Original-Received: from DM5PR03MB3163.namprd03.prod.outlook.com ([fe80::c75b:8346:2a6a:fdcf]) by DM5PR03MB3163.namprd03.prod.outlook.com ([fe80::c75b:8346:2a6a:fdcf%4]) with mapi id 15.20.6907.021; Wed, 18 Oct 2023 15:47:01 +0000 In-Reply-To: (Stefan Kangas's message of "Wed, 6 Sep 2023 15:46:28 -0700") X-Hashcash: 1:20:231018:57367@debbugs.gnu.org::qwLmoxK/ysSB3hej:0uQl X-Hashcash: 1:20:231018:larsi@gnus.org::LQhKvk1dXTWPs7qN:4rOI X-Hashcash: 1:20:231018:jporterbugs@gmail.com::i5+6PGHeO9qJtwxz:hmC X-Hashcash: 1:20:231018:stefankangas@gmail.com::s78X1M+gc4DGo/ph:3n+v X-TMN: [OHeCfx5Ked05h4LbJD8qh6poRvPHOiLb] X-ClientProxiedBy: YQBPR01CA0006.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:c01::14) To DM5PR03MB3163.namprd03.prod.outlook.com (2603:10b6:4:40::24) X-Microsoft-Original-Message-ID: <8734y8ndam.fsf_-_@outlook.com> X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM5PR03MB3163:EE_|CH2PR03MB5350:EE_ X-MS-Office365-Filtering-Correlation-Id: d0fc3018-b04f-4017-4f2f-08dbcff1782f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WmfXrQOU+bVC2lYjEhiCxtL1PvO4suAS7BC9wI7655Ua4opUfxgqFg1EXHwtUTK3ohiwc0uuiv65iN71Cx+JKQcmIJmp805c8edVEJfwWqcgR0TTascLCFvuEA5U+LYpqGHiTGgndXeDXmA9ri3nHM+TMKXtCsCiAo7KP1iSkkozY1AyiVNrA6K06G+t9fe0Wa96gGtKHPXC9ocPa9n/0dmyUdQrz+YBqbT4Nztp7AJj4UeLoIW/G+EL0F3BD5p+LQmykNFhFt6ZI5Z4Xhmm5oukYX6xSLztevPU+70ENcFjCFG9QjqanLH6qV9q7uOHlhrgvLxxLnAbLy+DNmYl43Y74M6QM+1oXoBv+os5XQPAeezoHUGmbhQSaY/fKWzbSuefqenXZi0lrOWJUAtvgMWlzaLABdHpukwxc6qJS4VC011fIJPxscCcfn8u1sNUZZ3fdBd+5J++CMDMgskrHDK8V3WpSZXtiN1PBeS4xues/hoxmS5Jxuf4uxo1GcFE1TV4j7yOFwBSy+Omfl86S4F9+6BF5OzjZDwsr/2i7U8FO85i1TeH/rPPRApaNbcg X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: nGqAqBfZ+JTB+2m6JTJK/Iopd8qg8EXuPl2PQWf117/3voSybVPDC4vmLf0VwVx78xGdXM0KNG7hQ2D671wOEP/89WJlqBnzfy1YcY16mF/hiGzuQuPItGCIvYAs0Qmpg4FMoYp4v5Q8qi6T9hn0dgltQ2vWVNxAmoioYBO0MufBCsY4BzWyW0QisNWr2Lsf8EUBjSQFiJzZoVUzmw/SrNQnY+3KruRUvMtHIZoY+Y53KN2lc7lhvtP+AT3wvHhW6fSUJS3uEz+F1UGXcJcpqKg50nGze6r4Hj6KBS1xst8P89RQ4T1DXxehl25yBwXefxBU+FlMMP/fsHpnUQDsisEIMrirxuQpSqli/b3ykexCxyN3mlfkeBJsjJaHOmzUaVAr5rMvEdE/qinX/kyETtaCQVgZQDFuLh0pdq5+sBYNsS8Jw5o1AWrszuPzAbK6a9V7vd9tqTen9I94pXchsOe4gYgrSP8ZPWzjhk4QUVxTYaeY9ddAZtQiMq9Hd8qS0oJFaiX9ipHdPRYQZoDdxD4PlvXss/BoWL3rkPQcrwxbaAD6ZZKN2CghPlbTm6LfF/QBYkwjkFm7IdNCuFnb0Ip9YXxCkuXmxvKKZ0DGul5O9ygR4mKX+4LR7+6rxdS0FwGlmtnqhVifrvPu3fK33CnweRGIeG1WXV0ToXqOr4tLOi9CCiazRl9sEJvQpoQbRtQD2Voo8j0tdvnh9CCENVoki0s77VEBxdMYR0nBKM8OtIyf7BusiHwwu9 An2ISc+ZHvf3DiJ76VWFj9QNjViPfDiZ8pt230lYJuBj5zaDcN5QJwM4nEqAtA6oTBJ6yBF1iNmodHdZvjjKPmWOUPYC89mJag X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d0fc3018-b04f-4017-4f2f-08dbcff1782f X-MS-Exchange-CrossTenant-AuthSource: DM5PR03MB3163.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Oct 2023 15:47:01.8780 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR03MB5350 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:272664 Archived-At: --=-=-= Content-Type: text/plain Stefan Kangas writes: > Jim Porter writes: > >> On 9/6/2022 6:30 PM, Morgan Smith wrote: >>> 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). >> >> Thanks, this does indeed seem a lot faster. I do notice one small change in >> behavior though: after starting Eshell with the em-smart module loaded, run >> "echo hi" and then split the window vertically with 'C-x 2'. Before the patch, >> the window doesn't scroll. After the patch, the window is scrolled so that the >> "echo hi" block is at the top (i.e. the "Welcome to the Emacs shell" banner is >> hidden). >> >> The same sort of thing happens if you run a command with a lot of output first >> and then run "echo hi". Before splitting, the "echo hi" block is at the >> bottom. Without this patch, 'C-x 2' maintains that position (i.e. it scrolls the >> minimum amount of the previous command out of view so that you can see the >> most-recent command). With the patch, 'C-x 2' scrolls *all* of the previous >> command out of view, so the "echo hi" block is at the top. >> >> I think the pre-patch behavior is the most-usable: if you can fit all of the >> last command in the window, it should be at the bottom so that you can see (some >> of) the previous command. >> >> (I also saw some strange issue with resizing the windows via the mouse, but I >> can't reproduce it anymore. If I can figure out how trigger this reliably, I'll >> send an update. Sorry that's not very helpful at present...) > > That was one year ago. > > Morgan, did you get a chance to look into the issues Jim pointed out > above? Thanks for the ping. Reading the documentation for `window-configuration-change-hook' I found out I can run the scroll command only on updated windows. Furthermore, that hook selects the window which is nice. I believe the problems pointed out above stem from using `(point)` to scroll a window that wasn't actually selected. Anyways here is V3 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=v3-0001-Speed-up-em-smart.patch >From 801bcf3fb761f9f32423b2c46e7e1b68a2c2ecdc Mon Sep 17 00:00:00 2001 From: Morgan Smith Date: Tue, 6 Sep 2022 21:18:51 -0400 Subject: [PATCH v3] 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. By using fewer hooks and never explicitly calling `redisplay` (which was unnecessary) the performance issues go away. lisp/eshell/em-smart.el: (em-smart-unload-hook, eshell-smart-unload-hook): Remove `eshell-smart-scroll' instead of the now deleted `eshell-refresh-windows' (eshell-smart-displayed, eshell-currently-handling-window, eshell-refresh-windows): 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-redisplay): Rename to `eshell-smart-scroll'. Delete 'eobp' case. --- lisp/eshell/em-smart.el | 83 +++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 53 deletions(-) diff --git a/lisp/eshell/em-smart.el b/lisp/eshell/em-smart.el index 4c39a991ec6..f34a9ec0309 100644 --- a/lisp/eshell/em-smart.el +++ b/lisp/eshell/em-smart.el @@ -95,7 +95,7 @@ eshell-smart-unload-hook (list (lambda () (remove-hook 'window-configuration-change-hook - 'eshell-refresh-windows))) + 'eshell-smart-scroll))) "A hook that gets run when `eshell-smart' is unloaded." :type 'hook :group 'eshell-smart) @@ -159,9 +159,7 @@ eshell-where-to-jump ;;; Internal Variables: -(defvar eshell-smart-displayed nil) (defvar eshell-smart-command-done nil) -(defvar eshell-currently-handling-window nil) ;;; Functions: @@ -174,10 +172,9 @@ eshell-smart-initialize (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 'window-configuration-change-hook 'eshell-smart-scroll nil t) - (add-hook 'eshell-output-filter-functions 'eshell-refresh-windows t t) + (add-hook 'eshell-output-filter-functions 'eshell-smart-scroll-windows 90 t) (add-hook 'after-change-functions 'eshell-disable-after-change nil t) @@ -193,28 +190,15 @@ eshell-smart-initialize (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 ((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? - (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 + (with-selected-window wind + (eshell-smart-scroll))))) + 0 t)) (defun eshell-smart-display-setup () "Set the point to somewhere in the beginning of the last command." @@ -231,8 +215,7 @@ eshell-smart-display-setup (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) @@ -254,28 +237,22 @@ eshell-smart-maybe-jump-to-end (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 - (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 () + "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 (selected-window) + (pos-bol) t)) + (if (pos-visible-in-window-p (point-max) (selected-window)) + (save-excursion + (goto-char (point-max)) + (recenter -1) + (unless (pos-visible-in-window-p top-point (selected-window)) + (goto-char top-point) + (set-window-start (selected-window) + (pos-bol) t)))))) (defun eshell-smart-goto-end () "Like `end-of-buffer', but do not push a mark." @@ -323,7 +300,7 @@ eshell-smart-display-move (remove-hook 'pre-command-hook 'eshell-smart-display-move t)))) (defun em-smart-unload-hook () - (remove-hook 'window-configuration-change-hook #'eshell-refresh-windows)) + (remove-hook 'window-configuration-change-hook #'eshell-smart-scroll)) (provide 'em-smart) -- 2.41.0 --=-=-=--