Skip to content

Commit b95c5ad

Browse files
frekuigitster
authored andcommitted
Use kwset in pickaxe
Benchmarks in the hot cache case: before: $ perf stat --repeat=5 git log -Sqwerty Performance counter stats for 'git log -Sqwerty' (5 runs): 47,092,744 cache-misses # 2.825 M/sec ( +- 1.607% ) 123,368,389 cache-references # 7.400 M/sec ( +- 0.812% ) 330,040,998 branch-misses # 3.134 % ( +- 0.257% ) 10,530,896,750 branches # 631.663 M/sec ( +- 0.121% ) 62,037,201,030 instructions # 1.399 IPC ( +- 0.142% ) 44,331,294,321 cycles # 2659.073 M/sec ( +- 0.326% ) 96,794 page-faults # 0.006 M/sec ( +- 11.952% ) 25 CPU-migrations # 0.000 M/sec ( +- 25.266% ) 1,424 context-switches # 0.000 M/sec ( +- 0.540% ) 16671.708650 task-clock-msecs # 0.997 CPUs ( +- 0.343% ) 16.728692052 seconds time elapsed ( +- 0.344% ) after: $ perf stat --repeat=5 git log -Sqwerty Performance counter stats for 'git log -Sqwerty' (5 runs): 51,385,522 cache-misses # 4.619 M/sec ( +- 0.565% ) 129,177,880 cache-references # 11.611 M/sec ( +- 0.219% ) 319,222,775 branch-misses # 6.946 % ( +- 0.134% ) 4,595,913,233 branches # 413.086 M/sec ( +- 0.112% ) 31,395,042,533 instructions # 1.062 IPC ( +- 0.129% ) 29,558,348,598 cycles # 2656.740 M/sec ( +- 0.204% ) 93,224 page-faults # 0.008 M/sec ( +- 4.487% ) 19 CPU-migrations # 0.000 M/sec ( +- 10.425% ) 950 context-switches # 0.000 M/sec ( +- 0.360% ) 11125.796039 task-clock-msecs # 0.997 CPUs ( +- 0.239% ) 11.164216599 seconds time elapsed ( +- 0.240% ) So the kwset code is about 33% faster. Signed-off-by: Fredrik Kuivinen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fca65d4 commit b95c5ad

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,7 @@ LIB_H += graph.h
533533
LIB_H += grep.h
534534
LIB_H += hash.h
535535
LIB_H += help.h
536+
LIB_H += kwset.h
536537
LIB_H += levenshtein.h
537538
LIB_H += list-objects.h
538539
LIB_H += ll-merge.h
@@ -624,6 +625,7 @@ LIB_OBJS += hash.o
624625
LIB_OBJS += help.o
625626
LIB_OBJS += hex.o
626627
LIB_OBJS += ident.o
628+
LIB_OBJS += kwset.o
627629
LIB_OBJS += levenshtein.o
628630
LIB_OBJS += list-objects.o
629631
LIB_OBJS += ll-merge.o

diffcore-pickaxe.c

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "diff.h"
77
#include "diffcore.h"
88
#include "xdiff-interface.h"
9+
#include "kwset.h"
910

1011
struct diffgrep_cb {
1112
regex_t *regexp;
@@ -146,7 +147,7 @@ static void diffcore_pickaxe_grep(struct diff_options *o)
146147

147148
static unsigned int contains(struct diff_filespec *one,
148149
const char *needle, unsigned long len,
149-
regex_t *regexp)
150+
regex_t *regexp, kwset_t kws)
150151
{
151152
unsigned int cnt;
152153
unsigned long sz;
@@ -175,9 +176,12 @@ static unsigned int contains(struct diff_filespec *one,
175176

176177
} else { /* Classic exact string match */
177178
while (sz) {
178-
const char *found = memmem(data, sz, needle, len);
179-
if (!found)
179+
size_t offset = kwsexec(kws, data, sz, NULL);
180+
const char *found;
181+
if (offset == -1)
180182
break;
183+
else
184+
found = data + offset;
181185
sz -= found - data + len;
182186
data = found + len;
183187
cnt++;
@@ -195,6 +199,7 @@ static void diffcore_pickaxe_count(struct diff_options *o)
195199
unsigned long len = strlen(needle);
196200
int i, has_changes;
197201
regex_t regex, *regexp = NULL;
202+
kwset_t kws = NULL;
198203
struct diff_queue_struct outq;
199204
DIFF_QUEUE_CLEAR(&outq);
200205

@@ -209,6 +214,10 @@ static void diffcore_pickaxe_count(struct diff_options *o)
209214
die("invalid pickaxe regex: %s", errbuf);
210215
}
211216
regexp = &regex;
217+
} else {
218+
kws = kwsalloc(NULL);
219+
kwsincr(kws, needle, len);
220+
kwsprep(kws);
212221
}
213222

214223
if (opts & DIFF_PICKAXE_ALL) {
@@ -219,16 +228,16 @@ static void diffcore_pickaxe_count(struct diff_options *o)
219228
if (!DIFF_FILE_VALID(p->two))
220229
continue; /* ignore unmerged */
221230
/* created */
222-
if (contains(p->two, needle, len, regexp))
231+
if (contains(p->two, needle, len, regexp, kws))
223232
has_changes++;
224233
}
225234
else if (!DIFF_FILE_VALID(p->two)) {
226-
if (contains(p->one, needle, len, regexp))
235+
if (contains(p->one, needle, len, regexp, kws))
227236
has_changes++;
228237
}
229238
else if (!diff_unmodified_pair(p) &&
230-
contains(p->one, needle, len, regexp) !=
231-
contains(p->two, needle, len, regexp))
239+
contains(p->one, needle, len, regexp, kws) !=
240+
contains(p->two, needle, len, regexp, kws))
232241
has_changes++;
233242
}
234243
if (has_changes)
@@ -251,16 +260,17 @@ static void diffcore_pickaxe_count(struct diff_options *o)
251260
if (!DIFF_FILE_VALID(p->two))
252261
; /* ignore unmerged */
253262
/* created */
254-
else if (contains(p->two, needle, len, regexp))
263+
else if (contains(p->two, needle, len, regexp,
264+
kws))
255265
has_changes = 1;
256266
}
257267
else if (!DIFF_FILE_VALID(p->two)) {
258-
if (contains(p->one, needle, len, regexp))
268+
if (contains(p->one, needle, len, regexp, kws))
259269
has_changes = 1;
260270
}
261271
else if (!diff_unmodified_pair(p) &&
262-
contains(p->one, needle, len, regexp) !=
263-
contains(p->two, needle, len, regexp))
272+
contains(p->one, needle, len, regexp, kws) !=
273+
contains(p->two, needle, len, regexp, kws))
264274
has_changes = 1;
265275

266276
if (has_changes)
@@ -271,6 +281,8 @@ static void diffcore_pickaxe_count(struct diff_options *o)
271281

272282
if (opts & DIFF_PICKAXE_REGEX)
273283
regfree(&regex);
284+
else
285+
kwsfree(kws);
274286

275287
free(q->queue);
276288
*q = outq;

0 commit comments

Comments
 (0)