git » git-arr » commit 58d11b8

Remove unnecessary stat calls on the hot path

author Alberto Bertogli
2025-11-28 00:14:25 UTC
committer Alberto Bertogli
2025-11-28 00:20:10 UTC
parent 957aa424e4fb3b897c60547db422bbce5f6c24b0

Remove unnecessary stat calls on the hot path

This patch removes some unnecessary stat calls on the hot path, which provide
minor (~5%) speedups in the incremental generation test.

git-arr +5 -3

diff --git a/git-arr b/git-arr
index adb784f..add0d1b 100755
--- a/git-arr
+++ b/git-arr
@@ -366,8 +366,10 @@ def generate(output: str, only=None):
 
         if mtime:
             path_mtime: Union[float, int] = 0
-            if os.path.exists(path):
+            try:
                 path_mtime = os.stat(path).st_mtime
+            except FileNotFoundError:
+                pass
 
             # Make sure they're both float or int, to avoid failing
             # comparisons later on because of this.
@@ -395,8 +397,8 @@ def generate(output: str, only=None):
                 s = func_or_str(*args)
 
         dirname = os.path.dirname(path)
-        if not os.path.exists(dirname):
-            os.makedirs(dirname)
+        if dirname:
+            os.makedirs(dirname, exist_ok=True)
 
         open(path, "w").write(s)
         if mtime: