Hi,
The tramp is extremely slow on windows, and I found that tramp in
emacs will call git 4 times on startup.

In the emacs-release package, the `tramp-loaddefs.el` has the copy of
tramp-repository-branch, tramp-repository-version (these two variables
are marked as autoload), it will call git to initialize their values;
and when requiring the `trampvar.el`, these two variables will be
initialize with calling git again.  That will call git 4 times.

This patch tries to avoid these calls, improving the performance a lot.

Please help review the patch. Thanks.

Lin
From a798905bf47fc8e8be22c9f367e1065c5aa19711 Mon Sep 17 00:00:00 2001
From: Lin Sun <lin....@zoom.us>
Date: Sat, 27 Jul 2024 04:29:19 +0000
Subject: [PATCH] * trampvar.el.in (tramp-repository-branch,
 tramp-repository-version):   Avoid to call git for initializing the variables
 every time.

---
 lisp/trampver.el.in | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/lisp/trampver.el.in b/lisp/trampver.el.in
index 614f048..332a3b4 100644
--- a/lisp/trampver.el.in
+++ b/lisp/trampver.el.in
@@ -49,30 +49,32 @@
 
 ;;;###tramp-autoload
 (defconst tramp-repository-branch
-  (ignore-errors
-    ;; Suppress message from `emacs-repository-get-branch'.  We must
-    ;; also handle out-of-tree builds.
-    (let ((inhibit-message t)
-	  (dir (or (locate-dominating-file (locate-library "tramp") ".git")
-		   source-directory))
-	  debug-on-error)
-      (and (stringp dir) (file-directory-p dir)
-	   (executable-find "git")
-	   (emacs-repository-get-branch dir))))
+  (eval-when-compile
+    (ignore-errors
+      ;; Suppress message from `emacs-repository-get-branch'.  We must
+      ;; also handle out-of-tree builds.
+      (let ((inhibit-message t)
+            (dir (or (locate-dominating-file (locate-library "tramp") ".git")
+                     source-directory))
+            debug-on-error)
+        (and (stringp dir) (file-directory-p dir)
+             (executable-find "git")
+             (emacs-repository-get-branch dir)))))
   "The repository branch of the Tramp sources.")
 
 ;;;###tramp-autoload
 (defconst tramp-repository-version
-  (ignore-errors
-    ;; Suppress message from `emacs-repository-get-version'.  We must
-    ;; also handle out-of-tree builds.
-    (let ((inhibit-message t)
-	  (dir (or (locate-dominating-file (locate-library "tramp") ".git")
-		   source-directory))
-	  debug-on-error)
-      (and (stringp dir) (file-directory-p dir)
-	   (executable-find "git")
-	   (emacs-repository-get-version dir))))
+  (eval-when-compile
+    (ignore-errors
+      ;; Suppress message from `emacs-repository-get-version'.  We must
+      ;; also handle out-of-tree builds.
+      (let ((inhibit-message t)
+            (dir (or (locate-dominating-file (locate-library "tramp") ".git")
+                     source-directory))
+            debug-on-error)
+        (and (stringp dir) (file-directory-p dir)
+             (executable-find "git")
+             (emacs-repository-get-version dir)))))
   "The repository revision of the Tramp sources.")
 
 ;; Check for Emacs version.
-- 
2.34.1

Reply via email to