Skip to content

Commit 86abba8

Browse files
rctaygitster
authored andcommitted
xdiff/xprepare: use a smaller sample size for histogram diff
For histogram diff, we can afford a smaller sample size and thus a poorer estimate of the number of lines, as the hash table (rhash) won't be filled up/grown. This is safe as the final count of lines (xdf.nrecs) will be updated correctly anyway by xdl_prepare_ctx(). This gives us a small boost in performance. Signed-off-by: Tay Ray Chuan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9f37c27 commit 86abba8

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

xdiff/xprepare.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#define XDL_KPDIS_RUN 4
2727
#define XDL_MAX_EQLIMIT 1024
2828
#define XDL_SIMSCAN_WINDOW 100
29+
#define XDL_GUESS_NLINES1 256
30+
#define XDL_GUESS_NLINES2 20
2931

3032

3133
typedef struct s_xdlclass {
@@ -239,11 +241,20 @@ static void xdl_free_ctx(xdfile_t *xdf) {
239241

240242
int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
241243
xdfenv_t *xe) {
242-
long enl1, enl2;
244+
long enl1, enl2, sample;
243245
xdlclassifier_t cf;
244246

245-
enl1 = xdl_guess_lines(mf1) + 1;
246-
enl2 = xdl_guess_lines(mf2) + 1;
247+
/*
248+
* For histogram diff, we can afford a smaller sample size and
249+
* thus a poorer estimate of the number of lines, as the hash
250+
* table (rhash) won't be filled up/grown. The number of lines
251+
* (nrecs) will be updated correctly anyway by
252+
* xdl_prepare_ctx().
253+
*/
254+
sample = xpp->flags & XDF_HISTOGRAM_DIFF ? XDL_GUESS_NLINES2 : XDL_GUESS_NLINES1;
255+
256+
enl1 = xdl_guess_lines(mf1, sample) + 1;
257+
enl2 = xdl_guess_lines(mf2, sample) + 1;
247258

248259
if (!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
249260
xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) {

xdiff/xutils.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@
2424

2525

2626

27-
#define XDL_GUESS_NLINES 256
28-
29-
30-
3127

3228
long xdl_bogosqrt(long n) {
3329
long i;
@@ -159,12 +155,12 @@ void *xdl_cha_next(chastore_t *cha) {
159155
}
160156

161157

162-
long xdl_guess_lines(mmfile_t *mf) {
158+
long xdl_guess_lines(mmfile_t *mf, long sample) {
163159
long nl = 0, size, tsize = 0;
164160
char const *data, *cur, *top;
165161

166162
if ((cur = data = xdl_mmfile_first(mf, &size)) != NULL) {
167-
for (top = data + size; nl < XDL_GUESS_NLINES;) {
163+
for (top = data + size; nl < sample;) {
168164
if (cur >= top) {
169165
tsize += (long) (cur - data);
170166
if (!(cur = data = xdl_mmfile_next(mf, &size)))

xdiff/xutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void xdl_cha_free(chastore_t *cha);
3333
void *xdl_cha_alloc(chastore_t *cha);
3434
void *xdl_cha_first(chastore_t *cha);
3535
void *xdl_cha_next(chastore_t *cha);
36-
long xdl_guess_lines(mmfile_t *mf);
36+
long xdl_guess_lines(mmfile_t *mf, long sample);
3737
int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags);
3838
unsigned long xdl_hash_record(char const **data, char const *top, long flags);
3939
unsigned int xdl_hashbits(unsigned int size);

0 commit comments

Comments
 (0)