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 <rctay89@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tay Ray Chuan committed Jul 12, 2011 at 14:10 UTC 86abba801575892a8a2b161aa29518c1ed05e1f1
3 files changed +17 -10
xdiff/xprepare.c
+14 -3
@@ -26,6 +26,8 @@
26 #define XDL_KPDIS_RUN 4
27 #define XDL_MAX_EQLIMIT 1024
28 #define XDL_SIMSCAN_WINDOW 100
29 +#define XDL_GUESS_NLINES1 256
30 +#define XDL_GUESS_NLINES2 20
31
32
33 typedef struct s_xdlclass {
@@ -239,11 +241,20 @@ static void xdl_free_ctx(xdfile_t *xdf) {
241
242 int xdl_prepare_env(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
243 xdfenv_t *xe) {
242 - long enl1, enl2;
244 + long enl1, enl2, sample;
245 xdlclassifier_t cf;
246
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;
258
259 if (!(xpp->flags & XDF_HISTOGRAM_DIFF) &&
260 xdl_init_classifier(&cf, enl1 + enl2 + 1, xpp->flags) < 0) {
xdiff/xutils.c
+2 -6
@@ -24,10 +24,6 @@
24
25
26
27 -#define XDL_GUESS_NLINES 256
28 -
29 -
30 -
27
28 long xdl_bogosqrt(long n) {
29 long i;
@@ -159,12 +155,12 @@ void *xdl_cha_next(chastore_t *cha) {
155 }
156
157
162 -long xdl_guess_lines(mmfile_t *mf) {
158 +long xdl_guess_lines(mmfile_t *mf, long sample) {
159 long nl = 0, size, tsize = 0;
160 char const *data, *cur, *top;
161
162 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;) {
164 if (cur >= top) {
165 tsize += (long) (cur - data);
166 if (!(cur = data = xdl_mmfile_next(mf, &size)))
xdiff/xutils.h
+1 -1
@@ -33,7 +33,7 @@ void xdl_cha_free(chastore_t *cha);
33 void *xdl_cha_alloc(chastore_t *cha);
34 void *xdl_cha_first(chastore_t *cha);
35 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);
37 int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags);
38 unsigned long xdl_hash_record(char const **data, char const *top, long flags);
39 unsigned int xdl_hashbits(unsigned int size);