unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#71179: [PATCH] In rgrep, check matching files before excluding files
@ 2024-05-24 20:14 Spencer Baugh
  2024-05-24 20:45 ` Dmitry Gutov
  2024-05-25  6:36 ` Eli Zaretskii
  0 siblings, 2 replies; 23+ messages in thread
From: Spencer Baugh @ 2024-05-24 20:14 UTC (permalink / raw)
  To: 71179

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

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'


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-In-rgrep-check-matching-files-before-excluding-files.patch --]
[-- Type: text/patch, Size: 2851 bytes --]

From f94e7f15c77ff1d8b5736adc49bd1e9bd54c7270 Mon Sep 17 00:00:00 2001
From: Spencer Baugh <sbaugh@janestreet.com>
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


^ permalink raw reply related	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2024-06-02 10:46 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-24 20:14 bug#71179: [PATCH] In rgrep, check matching files before excluding files Spencer Baugh
2024-05-24 20:45 ` Dmitry Gutov
2024-05-24 20:54   ` Spencer Baugh
2024-05-25 12:31     ` Dmitry Gutov
2024-05-26  6:50       ` Juri Linkov
2024-05-26 12:48         ` Spencer Baugh
2024-05-26 12:56         ` Dmitry Gutov
2024-05-25  6:36 ` Eli Zaretskii
2024-05-25 12:26   ` Dmitry Gutov
2024-05-25 12:51     ` Eli Zaretskii
2024-05-25 13:03       ` Dmitry Gutov
2024-05-25 13:45         ` Eli Zaretskii
2024-05-25 13:58           ` Dmitry Gutov
2024-05-25 13:36       ` Spencer Baugh
2024-05-25 13:56         ` Eli Zaretskii
2024-05-25 14:02           ` Spencer Baugh
2024-05-25 14:13             ` Eli Zaretskii
2024-05-25 14:47               ` Dmitry Gutov
2024-05-25 15:07                 ` Eli Zaretskii
2024-05-26 13:42                   ` Spencer Baugh
2024-06-01 14:15                     ` Eli Zaretskii
2024-06-02 10:46                       ` Stefan Kangas
2024-05-25 14:51               ` Dmitry Gutov

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).