9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: [9front] git: speed up commit parsing
Date: Sat, 04 Sep 2021 18:53:17 -0400	[thread overview]
Message-ID: <8160E37CF4CC8FBDB5D32389B412691C@eigenstate.org> (raw)

regexec() was at the top of the profile, so I
removed it. This costs a few extra lines of
code, but the parsing isn't too complicated.

This cuts down the amount of time in finding
hairy least-common-ancestors by about 20%,
and moves the bottleneck to decompression.

---
diff e5c05ed4491bb5df233d15bf5b2334c806f21e2e 2ac33147fcdfac36c2c8c40da73b5e9cbc929353
--- a/sys/src/cmd/git/git.h	Sat Sep  4 17:58:31 2021
+++ b/sys/src/cmd/git/git.h	Sat Sep  4 18:32:20 2021
@@ -2,7 +2,6 @@
 #include <mp.h>
 #include <libsec.h>
 #include <flate.h>
-#include <regexp.h>
 
 typedef struct Conn	Conn;
 typedef struct Hash	Hash;
@@ -247,7 +246,6 @@
 #define isblank(c) \
 	(((c) != '\n') && isspace(c))
 
-extern Reprog	*authorpat;
 extern Objset	objcache;
 extern Hash	Zhash;
 extern int	chattygit;
--- a/sys/src/cmd/git/pack.c	Sat Sep  4 17:58:31 2021
+++ b/sys/src/cmd/git/pack.c	Sat Sep  4 18:32:20 2021
@@ -809,32 +809,33 @@
 static int
 parseauthor(char **str, int *nstr, char **name, vlong *time)
 {
-	char buf[128];
-	Resub m[4];
-	char *p;
-	int n, nm;
+	char *s, *p;
+	int i, tz;
 
 	if((p = strchr(*str, '\n')) == nil)
 		sysfatal("malformed author line");
-	n = p - *str;
-	if(n >= sizeof(buf))
-		sysfatal("overlong author line");
-	memset(m, 0, sizeof(m));
-	snprint(buf, n + 1, *str);
+	s = *str;
+	i = p - s;
 	*str = p;
-	*nstr -= n;
-	
-	if(!regexec(authorpat, buf, m, nelem(m)))
-		sysfatal("invalid author line %s", buf);
-	nm = m[1].ep - m[1].sp;
-	*name = emalloc(nm + 1);
-	memcpy(*name, m[1].sp, nm);
-	buf[nm] = 0;
+	*nstr -= i;
+
+	while(i > 0 && (s[i-1] == ' ' || s[i-1] == '\t'))
+		i--;
+	while(i > 0 && (s[i-1] != ' ' && s[i-1] != '\t'))
+		i--;
+	tz = atoi(s+i);
+
+	while(i > 0 && (s[i-1] == ' ' || s[i-1] == '\t'))
+		i--;
+	while(i > 0 && (s[i-1] != ' ' && s[i-1] != '\t'))
+		i--;
+	*time = atoll(s+i) + (tz/100)*3600 + (tz%100)*60;
+
+	while(i > 0 && (s[i-1] == ' ' || s[i-1] == '\t'))
+		i--;
+	*name = emalloc(i+1);
+	strecpy(*name, *name+i, s);
 	
-	nm = m[2].ep - m[2].sp;
-	memcpy(buf, m[2].sp, nm);
-	buf[nm] = 0;
-	*time = atoll(buf);
 	return 0;
 }
 
--- a/sys/src/cmd/git/util.c	Sat Sep  4 17:58:31 2021
+++ b/sys/src/cmd/git/util.c	Sat Sep  4 18:32:20 2021
@@ -4,7 +4,6 @@
 
 #include "git.h"
 
-Reprog *authorpat;
 Hash Zhash;
 
 int chattygit;
@@ -201,7 +200,6 @@
 	fmtinstall('Q', Qfmt);
 	inflateinit();
 	deflateinit();
-	authorpat = regcomp("[\t ]*(.*)[\t ]+([0-9]+)[\t ]+([\\-+]?[0-9]+)");
 	osinit(&objcache);
 }
 


                 reply	other threads:[~2021-09-04 22:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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

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

  git send-email \
    --in-reply-to=8160E37CF4CC8FBDB5D32389B412691C@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    /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.
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 NNTP newsgroup(s).