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 V2] Speed up em-smart Date: Tue, 06 Sep 2022 21:30:18 -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="28206"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) Cc: 57367@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Wed Sep 07 03:31:28 2022 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 1oVjuZ-0007B1-Ss for geb-bug-gnu-emacs@m.gmane-mx.org; Wed, 07 Sep 2022 03:31:28 +0200 Original-Received: from localhost ([::1]:36884 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oVjuY-0002jI-As for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 06 Sep 2022 21:31:26 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oVjuA-0002jA-Q9 for bug-gnu-emacs@gnu.org; Tue, 06 Sep 2022 21:31:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:36070) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oVjuA-0006yA-Hx for bug-gnu-emacs@gnu.org; Tue, 06 Sep 2022 21:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oVjuA-00060d-BR for bug-gnu-emacs@gnu.org; Tue, 06 Sep 2022 21:31:02 -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, 07 Sep 2022 01:31: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.166251423723062 (code B ref 57367); Wed, 07 Sep 2022 01:31:02 +0000 Original-Received: (at 57367) by debbugs.gnu.org; 7 Sep 2022 01:30:37 +0000 Original-Received: from localhost ([127.0.0.1]:53000 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oVjtl-0005zt-5T for submit@debbugs.gnu.org; Tue, 06 Sep 2022 21:30:37 -0400 Original-Received: from mail-dm6nam12olkn2082.outbound.protection.outlook.com ([40.92.22.82]:40059 helo=NAM12-DM6-obe.outbound.protection.outlook.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oVjth-0005ze-IX for 57367@debbugs.gnu.org; Tue, 06 Sep 2022 21:30:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S35zoZVQMrz99JEiEE1Srvh1O28hRhBMxSbafNyEKpmMoCZCaBF64/l/o3VZyKofLYPn0q0S5aS9oFbYG74EIE/+XklFEn6FcCj89h21TNKiWlwLmvjRP7dwupkGnmMbnRiGBnObmAp2nYwY68moo20DIaHuLuXI8/kpvCf4Lfh6nZN+z9iQYRxV1rZeqUqZVz2cnpfuaKeyILtjpyluWG7/vozV4LMDLrrt5obcbZKDq8m3SsSolRdHC3dJ72M8tV83TnApw97tJLE82dS6NOpghn1GCnl57rGXvh7N7F1FrF92i0mTCtmA9tTE05dfU8u2AMdDHz50inmUQBF4tA== 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=CBrVBydl/1hCsTWvRjBXDmvzGsL3pmfOzY9gAdockW4=; b=G2Vk4H+RtoFx8yST0HOAI4oTT5fU8nXlsT5+OEg3H/TbfgLvFP6su0l2tc4g3gRz97Wg6DZ3QFfxNVpbBLCbEUVZV9xQdiz0SYVzgRVwj1Hxen0JMIgXYZLMpR6jEBu3IQApFDfSY2XIhaQp13ANWGmfGDW0/lJAoDKT21qkx5XCt5EwSi4XYklnKKM7bouCDg3a7X1s19kn9XnPf0iY4GmDp+pGHyud3NflMZ7u+BlFBeIVwtwiey3lCnWwHe6t67s8HDfhoRQNF3uTLCMW73ytAgxsluGiy1SNPjhJnd2qgpgHGPlPMRa3Jx6wCw2R+q8HQKzfCZFKNP6XNPsnyA== 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=CBrVBydl/1hCsTWvRjBXDmvzGsL3pmfOzY9gAdockW4=; b=CNRy3fYhc9eswC3z2aWHZxrtthAZzzy6chWu5r3gwcy49tmrUS1KItWuF6KoM+F5NfP2pKxhS7oFqB7uZc+moaPFFzoYPEisYPaRAr3xt8Gn8w48Cz++yLZkmETXMUhxOSJJ5xbwg+51hcRxxH/7SBnnbciRHT0Ic+TQHctEnH1amYt6mvQ0qJzVJKQ4FwxGANQGLuZGqg+4HtYDOCnJaCcGSsZZ/UZWPWzou2eIzTc/r7uD/8p9eYvGeLKomGn3pgtKuaSwLdwSAiOrCskpR/M02NCOcEkP5rlBCtAu0V0PRDcE0APyjd9SF7cSmX52++H3EJ2KjDijTkp9HXShSw== Original-Received: from DM5PR03MB3163.namprd03.prod.outlook.com (2603:10b6:4:40::24) by BN8PR03MB5059.namprd03.prod.outlook.com (2603:10b6:408:d9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5588.10; Wed, 7 Sep 2022 01:30:20 +0000 Original-Received: from DM5PR03MB3163.namprd03.prod.outlook.com ([fe80::1cf8:e25b:a93b:ffac]) by DM5PR03MB3163.namprd03.prod.outlook.com ([fe80::1cf8:e25b:a93b:ffac%6]) with mapi id 15.20.5588.018; Wed, 7 Sep 2022 01:30:20 +0000 In-Reply-To: <87ilm0x1ol.fsf@gnus.org> (Lars Ingebrigtsen's message of "Tue, 06 Sep 2022 12:00:26 +0200") X-TMN: [o3NtAvVDCl+gkoaM/qfN13Kfoy9U6pRZ] X-ClientProxiedBy: YT3PR01CA0147.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:83::19) To DM5PR03MB3163.namprd03.prod.outlook.com (2603:10b6:4:40::24) X-Microsoft-Original-Message-ID: <87v8q02cph.fsf_-_@outlook.com> X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7385c8e6-b1a2-40d8-469b-08da907086f6 X-MS-TrafficTypeDiagnostic: BN8PR03MB5059:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AWWh06PNND6RqRX9EcxNfANE0rany+JeRDEHdNQDPH1Ms9/xOVZ3C1TwW/P2KtPc7AVo6sG4pjeBc7hCPLVxu7prWOwGvhKQFW1i1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Q+VxjWhLDpBd9jV2NwW5calGooUjY14f2PzaEQf5q3v9Z0ZQLp4Jp0gZzzwMPaOT6gy5LxwLqqKoN15Kg9dsCciFDelpQAzIbsaNSfgeuk+dM4QKBIZ7Otb2CJeDCdyshP9GR2qsmZqRs86uQnl8UFdnPEpXLdweyufGDrRxMfWwe2oe7bcJJHt2NaG3WiWWrkrIUm1vZrztDs9/ByBgAhK8+8a3gaN6t5kWOzKdeH1zk8C+WPH2Mq1dWxD+s/U5BMGPDUhh7lyBQmd5uWdcIO1QOT2tttShp/xk4TVa5J4U8tRTd/2MrZ5+6O0ynm8TwUSHspwWR+WKgGOwHwPolkig5b qi4PbNB34vJbpFh0mpXRbnRjlhYRJpbpXmNT/95rLZ8IiYcreefwAD4/0uOeQNHzgpWUPpRDSotDUPaKLmhCdtOCMYRVOZiUpZ X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7385c8e6-b1a2-40d8-469b-08da907086f6 X-MS-Exchange-CrossTenant-AuthSource: DM5PR03MB3163.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2022 01:30:20.4495 (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: BN8PR03MB5059 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" Xref: news.gmane.io gmane.emacs.bugs:241713 Archived-At: --=-=-= Content-Type: text/plain 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). --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Speed-up-em-smart.patch >From 9e5b3d44019d08e12f95e5cc06c2273e3030e1bb Mon Sep 17 00:00:00 2001 From: Morgan Smith 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 --=-=-= Content-Type: text/plain Lars Ingebrigtsen 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 --=-=-=--