unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Albinus <michael.albinus@gmx.de>
To: Dmitry Gutov <dgutov@yandex.ru>
Cc: "Felicián Németh" <felician.nemeth@gmail.com>, 34343@debbugs.gnu.org
Subject: bug#34343: [PATCH] Make project--find-regexp-in-files work with remote files
Date: Fri, 03 Jan 2020 10:28:07 +0100	[thread overview]
Message-ID: <87blrksxco.fsf@gmx.de> (raw)
In-Reply-To: <ba375397-ecad-ca53-3634-aa35829c3bb6@yandex.ru> (Dmitry Gutov's message of "Fri, 3 Jan 2020 03:52:27 +0300")

Dmitry Gutov <dgutov@yandex.ru> writes:

> But most importantly for now: tramp-handle-file-remote-p does not take
> up the majority of time spent in
> file-remote-p. tramp-file-name-handler does:
>
> ELISP> (benchmark 10000 '(file-remote-p "/ssh:abc@def.com:/%d"
>                                  nil t))
> "Elapsed time: 3.535115s (2.112970s in 27 GCs)"
>
> ELISP> (benchmark 10000 '(tramp-handle-file-remote-p
> "/ssh:abc@def.com:/%d" nil t))
> "Elapsed time: 0.780867s (0.645621s in 8 GCs)"
>
> ELISP> (benchmark 10000 '(find-file-name-handler "/ssh:abc@def.com:/"
> 'file-remote-p))
> "Elapsed time: 0.070135s"
>
> ELISP> (benchmark 10000 '(tramp-file-name-handler 'file-remote-p
> "/ssh:abc@def.com:/%d"  nil t))
> "Elapsed time: 3.409674s (2.070461s in 27 GCs)"
>
> And that function does a lot of things that I'm not sure we need to
> just get the remote id.

Yes. But in case you want to be generic (handling all possible remote
file names, not only the Tramp implementation), you must use the file
name handler implementation, as it is described in
(info "(elisp) Magic File Names")

In case you want to go your own path, I could provide you an own
tramp-file-local-name function, which bypasses this mechanism:

--8<---------------cut here---------------start------------->8---
;; This function bypasses the file name handler approach.  It is NOT
;; recommended to use it in any package if not absolutely necessary,
;; because it won't work for remote file names not supported by Tramp.
;; However, it is more performant than `file-local-name', and might be
;; useful where performance matters, like in operations over a bulk
;; list of file names.
(defun tramp-file-local-name (file)
  "Return the local name component of FILE.
This function removes from FILE the specification of the remote
host and the method of accessing the host, leaving only the part
that identifies FILE locally on the remote system.  FILE must be
a string that matches `tramp-file-name-regexp'.
The returned file name can be used directly as argument of
‘process-file’, ‘start-file-process’, or ‘shell-command’."
  (and (tramp-tramp-file-p file)
       (string-match (nth 0 tramp-file-name-structure) file)
       (match-string (nth 4 tramp-file-name-structure) file)))
--8<---------------cut here---------------end--------------->8---

Here are the performance figures for local and remote files. I still use
the dolist construct in order to have different file names for every
file-local-name call; this avoids possible caching effects.

--8<---------------cut here---------------start------------->8---
(benchmark-run-compiled
    nil
  (let* ((dir "/path")
	 (remote (file-remote-p  dir)))
    (dotimes (i 10000)
      (if remote
	  (tramp-file-local-name (format "%s/%d" dir i))
	(format "%s/%d" dir i)))))

(0.09890154 1 0.07902910999999996)
--8<---------------cut here---------------end--------------->8---

--8<---------------cut here---------------start------------->8---
(benchmark-run-compiled
    nil
  (let* ((dir "/ssh:abc@def.com:/path")
	 (remote (file-remote-p  dir)))
    (dotimes (i 10000)
      (if remote
	  (tramp-file-local-name (format "%s/%d" dir i))
	(format "%s/%d" dir i)))))

(0.370237273 2 0.05851823899999997)
--8<---------------cut here---------------end--------------->8---

So it is four times slower for remote file names, but I believe the
numbers are acceptable. At least compared with file-local-name.





  reply	other threads:[~2020-01-03  9:28 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-06  8:18 bug#34343: [PATCH] Make project--find-regexp-in-files work with remote files Felicián Németh
2019-02-14  1:17 ` Dmitry Gutov
2019-02-15 18:53   ` Felicián Németh
     [not found]     ` <a54e7498-4ead-dd6f-6a2e-3919ab035b23@yandex.ru>
2019-02-27  9:15       ` Michael Albinus
2019-03-06  7:47         ` Felicián Németh
2019-03-06 14:33           ` Dmitry Gutov
2019-03-06 14:44             ` Dmitry Gutov
2019-03-08  8:28               ` Felicián Németh
2019-12-26 14:04                 ` Dmitry Gutov
2019-12-27  8:24                   ` Michael Albinus
2019-12-27 14:18                     ` Dmitry Gutov
2019-12-27 17:57                       ` Michael Albinus
2019-12-28 10:21                         ` Michael Albinus
2019-12-28 14:48                           ` Dmitry Gutov
2019-12-28 18:56                             ` Michael Albinus
2019-12-28 14:46                         ` Dmitry Gutov
2019-12-28 18:46                           ` Michael Albinus
2019-12-29  0:15                             ` Dmitry Gutov
2019-12-29 12:34                               ` Michael Albinus
2019-12-29 13:14                                 ` Dmitry Gutov
2020-01-01 12:29                                   ` Michael Albinus
2020-01-02  1:22                                     ` Dmitry Gutov
2020-01-02 10:48                                       ` Michael Albinus
2020-01-03  0:52                                         ` Dmitry Gutov
2020-01-03  9:28                                           ` Michael Albinus [this message]
2020-01-06 14:33                                             ` Dmitry Gutov
2020-01-06 18:48                                               ` Michael Albinus
2020-01-07  3:23                                                 ` Dmitry Gutov
2020-01-07  9:19                                                   ` Michael Albinus
2020-01-07 13:40                                                     ` Dmitry Gutov
2020-01-07 14:29                                                       ` Michael Albinus
2020-01-07 14:34                                                         ` Dmitry Gutov
2021-07-22 13:00                                                           ` Lars Ingebrigtsen
2021-07-24 19:42                                                             ` Dmitry Gutov
2021-07-25  6:41                                                               ` Lars Ingebrigtsen
2020-01-03  0:57                                         ` Dmitry Gutov
2020-01-06 17:29                     ` Felician Nemeth
2020-01-07  3:23                       ` Dmitry Gutov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87blrksxco.fsf@gmx.de \
    --to=michael.albinus@gmx.de \
    --cc=34343@debbugs.gnu.org \
    --cc=dgutov@yandex.ru \
    --cc=felician.nemeth@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).