]> git.eshelyaron.com Git - emacs.git/commitdiff
Prefer to run find and grep in parallel in rgrep (bug#71094)
authorSpencer Baugh <sbaugh@janestreet.com>
Wed, 3 Jul 2024 13:39:23 +0000 (15:39 +0200)
committerEshel Yaron <me@eshelyaron.com>
Wed, 3 Jul 2024 18:46:32 +0000 (20:46 +0200)
* lisp/progmodes/grep.el (grep-compute-defaults): Prefer `gnu' for
grep-find-use-xargs over `exec-plus', but not on Windows.  (bug#71094)

(cherry picked from commit f7725d85f3132fb684032438f81defcb481892b7)

lisp/progmodes/grep.el

index 7ac195017410561946dfcd0b5fecafb4df591331..826a66d6dbd92e802543487171192e67c36d6aed 100644 (file)
@@ -827,15 +827,23 @@ The value depends on `grep-command', `grep-template',
        (unless grep-find-use-xargs
          (setq grep-find-use-xargs
                (cond
-                ((grep-probe find-program
-                             `(nil nil nil ,(null-device) "-exec" "echo"
-                                   "{}" "+"))
-                 'exec-plus)
+                 ;; For performance, we want:
+                 ;; A. Run grep on batches of files (instead of one grep per file)
+                 ;; B. If the directory is large and we need multiple batches,
+                 ;;    run find in parallel with a running grep.
+                 ;; "find | xargs grep" gives both A and B
                 ((and
+                   (not (eq system-type 'windows-nt))
                   (grep-probe
                     find-program `(nil nil nil ,(null-device) "-print0"))
                   (grep-probe xargs-program '(nil nil nil "-0" "echo")))
                  'gnu)
+                 ;; "find -exec {} +" gives A but not B
+                ((grep-probe find-program
+                             `(nil nil nil ,(null-device) "-exec" "echo"
+                                   "{}" "+"))
+                 'exec-plus)
+                 ;; "find -exec {} ;" gives neither A nor B.
                 (t
                  'exec))))
        (unless grep-find-command