Subject: Re: bug#36857: 27.0.50; Reduce calls to xref-collect-matches in dired-do-find-regexp

From: Dmitry Gutov <[email-masked]>
Date: Wed, 25 Dec 2019 18:31:07 +0200

Hi Eric,

Please try the attached patch. It should cut down on the number of 
process calls.

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index fb1ad6266d..0fb8839a3f 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -2975,19 +2975,24 @@ dired-do-find-regexp
   (require 'xref)
   (defvar grep-find-ignored-files)
   (declare-function rgrep-find-ignored-directories "grep" (dir))
-  (let* ((files (dired-get-marked-files nil nil nil nil t))
+  (let* ((marks (dired-get-marked-files nil nil nil nil t))
          (ignores (nconc (mapcar
                           #'file-name-as-directory
                           (rgrep-find-ignored-directories default-directory))
                          grep-find-ignored-files))
          (fetcher
           (lambda ()
-            (let ((xrefs (mapcan
-                          (lambda (file)
-                            (xref-collect-matches regexp "*" file
-                                                  (and (file-directory-p file)
-                                                       ignores)))
-                          files)))
+            (let (files xrefs)
+              (mapc
+               (lambda (mark)
+                 (if (file-directory-p mark)
+                     (setq files (nconc
+                                  (project--files-in-directory mark ignores "*")
+                                  files))
+                   (push mark files)))
+               (nreverse marks))
+              (setq xrefs
+                    (project--find-regexp-in-files regexp files))
               (unless xrefs
                 (user-error "No matches for: %s" regexp))
               xrefs))))