From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Spencer Baugh Newsgroups: gmane.emacs.bugs Subject: bug#71179: [PATCH] In rgrep, check matching files before excluding files Date: Fri, 24 May 2024 16:14:39 -0400 Message-ID: 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="25446"; mail-complaints-to="usenet@ciao.gmane.io" To: 71179@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri May 24 22:15:13 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 1sAbJp-0006RE-84 for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 24 May 2024 22:15:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sAbJZ-0007kq-C8; Fri, 24 May 2024 16:14:57 -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 1sAbJX-0007is-D7 for bug-gnu-emacs@gnu.org; Fri, 24 May 2024 16:14:55 -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 1sAbJX-0007Sc-5c for bug-gnu-emacs@gnu.org; Fri, 24 May 2024 16:14:55 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sAbJe-0006GE-7g for bug-gnu-emacs@gnu.org; Fri, 24 May 2024 16:15:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 May 2024 20:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 71179 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.171658169824035 (code B ref -1); Fri, 24 May 2024 20:15:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 24 May 2024 20:14:58 +0000 Original-Received: from localhost ([127.0.0.1]:38970 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAbJZ-0006Fb-KA for submit@debbugs.gnu.org; Fri, 24 May 2024 16:14:58 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:55352) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sAbJX-0006FV-6G for submit@debbugs.gnu.org; Fri, 24 May 2024 16:14:55 -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 1sAbJL-0007ea-0Q for bug-gnu-emacs@gnu.org; Fri, 24 May 2024 16:14:44 -0400 Original-Received: from mxout5.mail.janestreet.com ([64.215.233.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sAbJJ-0007Q7-7a for bug-gnu-emacs@gnu.org; Fri, 24 May 2024 16:14:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=waixah; t=1716581679; bh=DVhkL6dJ4Dbtfxec5y5qqGmlKebTSK6Q4WG4e77H2Xs=; h=From:To:Subject:Date; b=1LjxrXNQ5QU2EptlOFZxW19JazFBO78HhaHAUSR7Wa01TkIlOF0BB08bgHqeWMkYZ Z6Sp0e7ibiuLMBs4EuZA22eL9x1/1j8acKNiFAgbN00v0FCPo7UiaruzjNqg+72Ei6 1m7P+5U+vMElkwxSL13MRmH4+J/IyKt7kAKmcVH9ZV7nvUt8epKvztL3lkvu148O9l mu+P9q4CVawz5AztpAP+dOdL2cPcwFypMSDR5t6G9yS8cfhd52F5iL17j2xbW0oS6e yiMCvmO8l5dx45Y6lsLrRFtQ9D7nxoFVyZgtrLu/nYgvHsYAxLOt7ZnIgnnXnPcGW6 CWm4NOYD6pKCg== Received-SPF: pass client-ip=64.215.233.18; envelope-from=sbaugh@janestreet.com; helo=mxout5.mail.janestreet.com 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, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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:285798 Archived-At: --=-=-= Content-Type: text/plain Tags: patch In rgrep, check matching files before excluding files There are a lot of excluding globs, and checking them all is expensive. The files glob (i.e. the glob for files we actually want) is usually just one or two entries, so it's quite fast to check. If find checks the files glob first and then the excluding glob, it has to do much less checking (since the files glob will substantially narrow down the set of files on its own), and find performance is much better. In my benchmarking, this takes (rgrep "foo" "*.el" "~/src/emacs/trunk/") from ~410ms to ~130ms. When the files glob is "* .*", there's no benefit from this change, since we still have to check every excluding glob anyway. But there's also no cost. * lisp/progmodes/grep.el (rgrep-default-command): Move the excluded files glob to part of the "files" argument. In GNU Emacs 29.2.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw scroll bars) of 2024-05-20 built on igm-qws-u22796a Repository revision: 734740051bd377d24899d08d00ec8e1bb8e00e00 Repository branch: emacs-29 Windowing system distributor 'The X.Org Foundation', version 11.0.12011000 System Description: Rocky Linux 8.9 (Green Obsidian) Configured using: 'configure -C --with-x-toolkit=lucid --with-gif=ifavailable --with-native-compilation=aot' --=-=-= Content-Type: text/patch Content-Disposition: attachment; filename=0001-In-rgrep-check-matching-files-before-excluding-files.patch >From f94e7f15c77ff1d8b5736adc49bd1e9bd54c7270 Mon Sep 17 00:00:00 2001 From: Spencer Baugh Date: Fri, 24 May 2024 13:12:28 -0400 Subject: [PATCH] In rgrep, check matching files before excluding files There are a lot of excluding globs, and checking them all is expensive. The files glob (i.e. the glob for files we actually want) is usually just one or two entries, so it's quite fast to check. If find checks the files glob first and then the excluding glob, it has to do much less checking (since the files glob will substantially narrow down the set of files on its own), and find performance is much better. In my benchmarking, this takes (rgrep "foo" "*.el" "~/src/emacs/trunk/") from ~410ms to ~130ms. * lisp/progmodes/grep.el (rgrep-default-command): Move the excluded files glob to part of the "files" argument. --- lisp/progmodes/grep.el | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el index ce54c57aabc..84b3b352faa 100644 --- a/lisp/progmodes/grep.el +++ b/lisp/progmodes/grep.el @@ -1383,7 +1383,17 @@ rgrep-default-command (split-string files) (concat " -o " find-name-arg " ")) " " - (shell-quote-argument ")" grep-quoting-style)) + (shell-quote-argument ")" grep-quoting-style) + (when-let ((ignored-files (grep-find-ignored-files dir))) + (concat " " (shell-quote-argument "!" grep-quoting-style) + " " (shell-quote-argument "(" grep-quoting-style) + ;; we should use shell-quote-argument here + " -name " + (mapconcat + (lambda (ignore) (shell-quote-argument ignore grep-quoting-style)) + ignored-files + " -o -name ") + " " (shell-quote-argument ")" grep-quoting-style)))) dir (concat (when-let ((ignored-dirs (rgrep-find-ignored-directories dir))) @@ -1398,18 +1408,6 @@ rgrep-default-command " -o -path ") " " (shell-quote-argument ")" grep-quoting-style) - " -prune -o ")) - (when-let ((ignored-files (grep-find-ignored-files dir))) - (concat (shell-quote-argument "!" grep-quoting-style) " -type d " - (shell-quote-argument "(" grep-quoting-style) - ;; we should use shell-quote-argument here - " -name " - (mapconcat - (lambda (ignore) (shell-quote-argument ignore grep-quoting-style)) - ignored-files - " -o -name ") - " " - (shell-quote-argument ")" grep-quoting-style) " -prune -o "))))) (defun grep-find-toggle-abbreviation () -- 2.39.3 --=-=-=--