Subject: Re: bug#34343: [PATCH] Make project--find-regexp-in-files work with remote files

From: Michael Albinus <[email-masked]>
Date: Wed, 01 Jan 2020 13:29:52 +0100

Dmitry Gutov <[email-masked]> writes:

>> Not always. But even if it calls expand-file-name, this doesn't mean
>> always that a remote command is fired. This is what is expensive.
>
> That depends on our performance goals. As described in
> https://debbugs.gnu.org/cgi/bugreport.cgi?bug=34343#29, when called on
> a lot of files, it can be fairly expensive even when offline.
>
> But eliminating remote calls will be a win, for sure.

I've played a little bit with this. Even if there is no remote file name
involved, file-local-name is slow due to the file-remote-p call and the
file name handler mechanery. See:

--8<---------------cut here---------------start------------->8---
(benchmark-run-compiled
    nil
  (dotimes (i 1000000) (format "/tmp/%d" i)))

=> (1.720033035 16 1.2495203040000007)
--8<---------------cut here---------------end--------------->8---

This is my initial example. Evall'ing `format' 1.000.000 times.

--8<---------------cut here---------------start------------->8---
(benchmark-run-compiled
    nil
  (dotimes (i 1000000) (file-local-name (format "/tmp/%d" i))))

=> (5.072258441 16 1.2559830709999957)
--8<---------------cut here---------------end--------------->8---

Although still a local file name, the elapsed time is about three times
as large in the initial example.

--8<---------------cut here---------------start------------->8---

(benchmark-run-compiled
    nil
  (let ((remote (file-remote-p  "/tmp")))
    (dotimes (i 1000000)
      (if remote
	  (file-local-name (format "%s/%d" remote i))
	(format "%s/%d" remote i)))))

=> (1.831333636 16 1.2604051830000103)
--8<---------------cut here---------------end--------------->8---

Refactoring the code, and applying `file-local-name' just to the cases
where it is needed, shows an elapsed time similar to the initial one.

Best regards, Michael.