From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Morgan Willcock Newsgroups: gmane.emacs.bugs Subject: bug#73533: [PATCH] Rewrite speedbar expansion for all descendants Date: Sat, 28 Sep 2024 20:05:26 +0100 Message-ID: <87y13blhu1.fsf@ice9.digital> 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="22151"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) To: 73533@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Sep 28 22:01:59 2024 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 1suddf-0005ZV-CO for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 28 Sep 2024 22:01:59 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1suddI-0004ej-Sd; Sat, 28 Sep 2024 16:01:36 -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 1suddE-0004dt-Vu for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 16:01:34 -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 1suddE-0007kG-M5 for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 16:01:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=0lpE61LCFx+yDgjVjJm4fg5kzoBcQv4GlKyA5Q8hpy8=; b=kIAsiFT0nUCdtR6zben+7/Hb+eZKVXFD8SVWJa7D1kSAWOhYNoZJ6sNpjhIugSUTKiH+nVC2EAg7slCDJNnMOf5O1iH73iAhUpOuiN5dMPieQc9BLkcCazKtlQ/XyyLOETtxVEPHuyuBJMh9O3EQH0ust/F15qqJ2oe98mHMmBSIci3bEtDsdV16gnY2Do7YAh/TWFaoftHqNfvpiQCc7qheDmt5Tvfzs1wXX/wVOpOL+ZzOVX2u/svJkMOs2EQptSOBsgxN7dWoIVVbWUE2CHCCEYzqtP1o/fwybTFNnFeoBY9b1I3u1XKlZ454hYIZMTi84lYSmuXwOq87FBQyJw==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1suddi-0001SM-Sp for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 16:02:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Morgan Willcock Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 28 Sep 2024 20:02:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73533 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.17275536675320 (code B ref -1); Sat, 28 Sep 2024 20:02:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 28 Sep 2024 20:01:07 +0000 Original-Received: from localhost ([127.0.0.1]:43274 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sudcp-0001Nj-5N for submit@debbugs.gnu.org; Sat, 28 Sep 2024 16:01:07 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:50560) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sudcj-0001MY-QE for submit@debbugs.gnu.org; Sat, 28 Sep 2024 16:01:03 -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 1sucl5-0008Jv-QD for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 15:05:35 -0400 Original-Received: from relay4-d.mail.gandi.net ([2001:4b98:dc4:8::224]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sucl3-0001GE-2r for bug-gnu-emacs@gnu.org; Sat, 28 Sep 2024 15:05:35 -0400 Original-Received: by mail.gandi.net (Postfix) with ESMTPSA id D22BBE0002 for ; Sat, 28 Sep 2024 19:05:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ice9.digital; s=gm1; t=1727550327; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=0lpE61LCFx+yDgjVjJm4fg5kzoBcQv4GlKyA5Q8hpy8=; b=THFnAtf4gb+DZMtfPZ1OHcV6iso+jL/Aznt+QOSNTV4Zw0ETAyOO+oc0WOFdwBw1XTW7bt sEws/XKU6B9n7W+LvzJhBBHaDzVJx2PRGXT367PbqyD/Vx0AW38o4CMQArYUEaC4ekadsp dXlv4JriQGrSVxYQLMJcREMwpX6iypPBU0CTrK5PWNiwxHvJKrx2yawtjcVsBUrjCjJqhd rYNnZ3tMAPpD5FAy5Jctttsa8xrqsV3QaRcxjbAUxp+g0ZdJ/QoXBgLGzfJTxxGoJ+43+R FQUIaafiXyZAJH3/pcXRDY675C8Bn6f8Sh5tl8klaebUZJJy/VJRdnP12u1BqQ== X-GND-Sasl: morgan@ice9.digital Received-SPF: pass client-ip=2001:4b98:dc4:8::224; envelope-from=morgan@ice9.digital; helo=relay4-d.mail.gandi.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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:292604 Archived-At: --=-=-= Content-Type: text/plain Tags: patch Attached is a patch which rewrites 'speedbar-expand-line-descendants'. The previous version could get into an infinite loop by reaching the maximum recursion depth, although in practice the slow speed meant that most people would probably abort the operation before reaching that point. The majority of the slowdown was because the motion commands being used were the variants which looked up information for every entry, displayed the information as a message, and adjusted the cursor position. The messages were not readable because of being continually overwritten. Here is a way to demonstrate that stack depth was increasing for items at the same level, that the messages were not readable, and how slow the whole process was: rm -rf /tmp/project mkdir /tmp/project for i in $(seq 1 50); do echo "(defun fun-$i ())" >> /tmp/project/file1.el; done for i in $(seq 1 50); do echo "(defun fun-$i ())" >> /tmp/project/file2.el; done emacs -Q \ --eval="(find-file \"/tmp/project/file1.el\")" \ --eval "(speedbar-get-focus)" \ --eval "(profiler-start 'cpu)" \ --eval "(speedbar-expand-line-descendants)" \ --eval "(profiler-stop)" \ --eval "(profiler-report)" ...that should expand every entry in file1.el and not touch the entries in file2.el. The replacement function is significantly faster. Messages are only used to indicate that the function is running and when it is finished - the result is similar to manually clicking every node open. Thanks, Morgan In GNU Emacs 30.0.91 (build 2, x86_64-pc-linux-gnu, X toolkit, cairo version 1.16.0, Xaw3d scroll bars) of 2024-09-12 built on inspiron Windowing system distributor 'The X.Org Foundation', version 11.0.12101007 System Description: Debian GNU/Linux 12 (bookworm) Configured using: 'configure --with-native-compilation=aot --with-xml2 --with-x-toolkit=lucid' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-Rewrite-speedbar-expansion-for-all-descendants.patch >From 0e25d28bfbef31c20ec22c2e508933b3824a8172 Mon Sep 17 00:00:00 2001 From: Morgan Willcock Date: Sat, 28 Sep 2024 19:11:11 +0100 Subject: [PATCH] Rewrite speedbar expansion for all descendants Rewrite 'speedbar-expand-line-descendants' to avoid getting into an infinite loop by reaching max-lisp-eval-depth. The new method avoids querying and displaying information for every movement, instead using a single message to indicate that expansion is in progress, and so is significantly faster. * lisp/speedbar.el (speedbar-expand-line-descendants): Use simpler line motion and no recursion. Output messages indicating when expansion is in progress and when it is completed. --- lisp/speedbar.el | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lisp/speedbar.el b/lisp/speedbar.el index c13c977938b..11e11e1e56c 100644 --- a/lisp/speedbar.el +++ b/lisp/speedbar.el @@ -3172,21 +3172,22 @@ speedbar-expand-line-descendants "Expand the line under the cursor and all descendants. Optional argument ARG indicates that any cache should be flushed." (interactive "P") - (save-restriction - (narrow-to-region (line-beginning-position) - (line-beginning-position 2)) - (speedbar-expand-line arg) - ;; Now, inside the area expanded here, expand all subnodes of - ;; the same descendant type. - (save-excursion - (speedbar-next 1) ;; Move into the list. - (let ((err nil)) - (while (not err) - (condition-case nil - (progn - (speedbar-expand-line-descendants arg) - (speedbar-restricted-next 1)) - (error (setq err t)))))))) + (dframe-message "Expanding all descendants...") + (save-excursion + (with-restriction + ;; Narrow around the top-level item. + (line-beginning-position) + (condition-case nil + (save-excursion + (speedbar-restricted-move 1) + (line-beginning-position)) + (error (line-beginning-position 2))) + ;; Expand every line until the end of the restriction. + (while (zerop (progn + (speedbar-expand-line arg) + (forward-line 1)))))) + (dframe-message "Expanding all descendants...done") + (speedbar-position-cursor-on-line)) (defun speedbar-contract-line-descendants () "Expand the line under the cursor and all descendants." -- 2.39.5 --=-=-=--