From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Michael Albinus Newsgroups: gmane.emacs.bugs Subject: bug#34343: [PATCH] Make project--find-regexp-in-files work with remote files Date: Fri, 03 Jan 2020 10:28:07 +0100 Message-ID: <87blrksxco.fsf@gmx.de> References: <87r2bt1tio.fsf@gmx.de> <2cfd53b2-8202-a321-a853-da0c949b0f15@yandex.ru> <6cf8bfa8-3873-d3db-9139-854359027e8a@yandex.ru> <87h81mqiq5.fsf@gmx.de> <0ff03b20-20d8-b6c0-c876-3fd525586180@yandex.ru> <87mubdps6s.fsf@gmx.de> <87blrsz3tf.fsf@gmx.de> <87blrrmht9.fsf@gmx.de> <87tv5fs6kf.fsf@gmx.de> <7a1e2e22-89d4-b8b9-6cd4-e6947436138c@yandex.ru> <87mub6uoa6.fsf@gmx.de> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="246882"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: =?UTF-8?Q?Felici=C3=A1n_?= =?UTF-8?Q?N=C3=A9meth?= , 34343@debbugs.gnu.org To: Dmitry Gutov Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jan 03 10:29:32 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1inJGs-001257-64 for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 Jan 2020 10:29:30 +0100 Original-Received: from localhost ([::1]:50336 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1inJGq-0004ju-64 for geb-bug-gnu-emacs@m.gmane.org; Fri, 03 Jan 2020 04:29:28 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50704) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1inJGR-0004jo-Nr for bug-gnu-emacs@gnu.org; Fri, 03 Jan 2020 04:29:05 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1inJGQ-0008TV-Fx for bug-gnu-emacs@gnu.org; Fri, 03 Jan 2020 04:29:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:34426) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1inJGQ-0008Sl-3k for bug-gnu-emacs@gnu.org; Fri, 03 Jan 2020 04:29:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1inJGQ-0002nX-0z for bug-gnu-emacs@gnu.org; Fri, 03 Jan 2020 04:29:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Michael Albinus Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 03 Jan 2020 09:29:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 34343 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 34343-submit@debbugs.gnu.org id=B34343.157804369810698 (code B ref 34343); Fri, 03 Jan 2020 09:29:01 +0000 Original-Received: (at 34343) by debbugs.gnu.org; 3 Jan 2020 09:28:18 +0000 Original-Received: from localhost ([127.0.0.1]:40399 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1inJFi-0002mU-GX for submit@debbugs.gnu.org; Fri, 03 Jan 2020 04:28:18 -0500 Original-Received: from mout.gmx.net ([212.227.15.19]:47133) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1inJFg-0002mF-EQ for 34343@debbugs.gnu.org; Fri, 03 Jan 2020 04:28:17 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1578043688; bh=cIfchYXQdaM2insG6f0+RLTARwaySZvUq0pbyiTJKr0=; h=X-UI-Sender-Class:From:To:Cc:Subject:References:Date:In-Reply-To; b=eczsqx/rebeQWtYnrzcn0+xaDEjNsIgGBW7oAnr/8PlO6kBLJEJ5TaIA3Og17ELDe TSyG1C6pUHo8x7hTSr4grg+Oj4tvZ8dQhCuNeYFGd2UWVh3YEnJWrvxs6wdSdUQTIA N39s0v5wu+0TAnL6ZzDeWlunOcE8ywdzYgP8/5Po= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Original-Received: from detlef.gmx.de ([212.86.57.135]) by mail.gmx.com (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MoO2E-1jXggK24FM-00oqQV; Fri, 03 Jan 2020 10:28:08 +0100 In-Reply-To: (Dmitry Gutov's message of "Fri, 3 Jan 2020 03:52:27 +0300") X-Provags-ID: V03:K1:i93ZbVAGrH/LFXQqaS21gr2fFOlBnyWiO4A4z7hz32USeP6RDzy vjm98bRBIg0099UyPrTIPiAyLNQqs+kaln2Ih+ISOwIGHTxKyCDm8Lyee9ysoEoLb771Jfe QWMHg6+h/Z+Wopxv5R30LdQ2iKhvrlpFqH0UwDLPJJdfM2Mx4EkWUFGB4IKnq/cj/pViMM8 4QPA3nS072xrxOk3ryywg== X-UI-Out-Filterresults: notjunk:1;V03:K0:v8gl35L9PW8=:KnNKsmzZ0Uo51F/ce/ZB3C FA4L4yhg5Gb1hgTF+dYhDFqw1B0/I6sSj2joexLAttiwbvUHjwGoD/itQ2jpyYNH6kKNeBBMA GxdxyYpWQ0F1DqCsd/52CXGB8dp87TUd6yRojRqvHk6DjtKR4GDCO18st1xEr1VJR2WZ+jzS2 t+/9ozOWciXqU0sgEYDXk/Iyxz0tRukTKR2AfHc4O0WRUBRC/aaacRf8+/IQ8yUhiRNjMo0nF Jmsn1OtuZWAQeGiWBlDkQ4tiBOhUTH54kydvIt7N1q6l5wg5JKdZUiXzS0fY5hA+8/6L4IvaK hqOHjzMEOQonwMzu1abFK3FjgXFY6U6VX9ApsADpVrmXcKWajEbX+Gi00j+V+E+WZO7jurk3E deyA3SxqZ/qiZvclSMaHNZk3oGbLFqWGRi/edJL8tTfNqCw14Mfl1Ym/ZC6NS9VhhAy0wa6d1 Brx1jffOLGmIVysumhoA7TN5p5lULqXWuqVbUk9GgAGI6AURxyZxIsijFzmwfTwOG4O+5VysR 8KrR7XleSzec+J5EtjJpnrslkPqyrII+hMzbcz0e7jfzwI4y6gLuRGKt/66ofJFfX3xmD0Sla 6vR6Z9Tz9DcZj5FmvkzIbu4QoUw5yDiT1Su6WwnycIknizV6pzhdV06wEJn4rh+gvfzy/OQ1J jGCcRzXie/sDe4M6oKaO5idpC2O4FDKU8r3CADkhxkOjo88/Ru4TOuQYvOObtqhwzijtF7kTN dxLOIiRvEhmArWOGQIQHpwQ+Vok5aLeusZjvbJyj5YQC3gXd6YI63XtuJmseDnWPRJRgeil4 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:174104 Archived-At: Dmitry Gutov 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 =E2=80=98process-file=E2=80=99, =E2=80=98start-file-process=E2=80=99, or = =E2=80=98shell-command=E2=80=99." (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.