From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12307 invoked from network); 4 Sep 2021 22:58:10 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 4 Sep 2021 22:58:10 -0000 Received: from mimir.eigenstate.org ([206.124.132.107]) by 4ess; Sat Sep 4 18:53:56 -0400 2021 Received: from abbatoir.myfiosgateway.com (pool-74-108-56-225.nycmny.fios.verizon.net [74.108.56.225]) by mimir.eigenstate.org (OpenSMTPD) with ESMTPSA id 84673b57 (TLSv1.2:ECDHE-RSA-AES256-SHA:256:NO) for <9front@9front.org>; Sat, 4 Sep 2021 15:53:18 -0700 (PDT) Message-ID: <8160E37CF4CC8FBDB5D32389B412691C@eigenstate.org> To: 9front@9front.org Date: Sat, 04 Sep 2021 18:53:17 -0400 From: ori@eigenstate.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: information rich-client optimizer Subject: [9front] git: speed up commit parsing Reply-To: 9front@9front.org Precedence: bulk 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 #include #include -#include 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); }