shithub: git9

Download patch

ref: 76566d81a8e51d8d8255c9d6a8e7cd107fc6de01
parent: 02199f94227871b32a4019292bdf1c731be99cee
author: Ori Bernstein <[email protected]>
date: Mon Mar 9 00:49:29 EDT 2020

speed up git/walk massively

Don't stat the files on git/fs from git/walk: this
is not very fast, since on the first access (and if
we fall out of cache), we need to decompress all
the data. This is slow.

Only looking at the qid takes git/walk from 20+
seconds on the perl repository to just about 1
second.

--- a/add
+++ b/add
@@ -37,8 +37,11 @@
 		delpath=.git/index9/$del/$f
 		mkdir -p `{basename -d $addpath}
 		mkdir -p `{basename -d $delpath}
+		# We don't want a matching qid, so that
+		# git/walk doesn't think this came from
+		# a checkout.
 		if(! test -e $addpath)
-			walk -eq $f > $addpath
+			touch $addpath
 		rm -f $delpath
 	}
 }
--- a/walk.c
+++ b/walk.c
@@ -295,21 +295,27 @@
 		rpath = smprint(RDIR"/%s", p);
 		tpath = smprint(TDIR"/%s", p);
 		bpath = smprint(HDIR"/%s", p);
-		if(d == nil || access(rpath, AEXIST) == 0){
-			dirty |= Rflg;
-			if(!quiet && (printflg & Rflg))
-				print("%s%s\n", rstr, p);
-		}else if(access(bpath, AEXIST) == -1) {
-			dirty |= Aflg;
-			if(!quiet && (printflg & Aflg))
-				print("%s%s\n", astr, p);
-		}else if(sameqid(d, tpath) || samedata(p, bpath)){
+		/* Fast path: we don't want to force access to the rpath. */
+		if(d && sameqid(d, tpath)) {
 			if(!quiet && (printflg & Tflg))
 				print("%s%s\n", tstr, p);
-		}else{
-			dirty |= Mflg;
-			if(!quiet && (printflg & Mflg))
-				print("%s%s\n", mstr, p);
+		} else {
+			if(d == nil || access(rpath, AEXIST) == 0){
+				dirty |= Rflg;
+				if(!quiet && (printflg & Rflg))
+					print("%s%s\n", rstr, p);
+			}else if(access(bpath, AEXIST) == -1) {
+				dirty |= Aflg;
+				if(!quiet && (printflg & Aflg))
+					print("%s%s\n", astr, p);
+			}else if(samedata(p, bpath)){
+				if(!quiet && (printflg & Tflg))
+					print("%s%s\n", tstr, p);
+			}else{
+				dirty |= Mflg;
+				if(!quiet && (printflg & Mflg))
+					print("%s%s\n", mstr, p);
+			}
 		}
 		free(rpath);
 		free(tpath);