From: Brian Downing <bdowning@lavos.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, Brian Downing <bdowning@lavos.net>
Subject: [PATCHv2 2/2] Use strbuf for struct xdiff_emit_state's remainder
Date: Thu, 14 Aug 2008 00:13:22 -0500 [thread overview]
Message-ID: <1218690802-30536-2-git-send-email-bdowning@lavos.net> (raw)
In-Reply-To: <1218690802-30536-1-git-send-email-bdowning@lavos.net>
Continually xreallocing and freeing the remainder member of struct
xdiff_emit_state was a noticeable performance hit. Use a strbuf
instead.
This yields a decent performance improvement on "git blame" on certain
repositories. For example, before this commit:
$ time git blame -M -C -C -p --incremental server.c >/dev/null
101.52user 0.17system 1:41.73elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+39561minor)pagefaults 0swaps
With this commit:
$ time git blame -M -C -C -p --incremental server.c >/dev/null
80.38user 0.30system 1:20.81elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (0major+50979minor)pagefaults 0swaps
Signed-off-by: Brian Downing <bdowning@lavos.net>
---
xdiff-interface.c | 32 ++++++++++----------------------
xdiff-interface.h | 4 ++--
2 files changed, 12 insertions(+), 24 deletions(-)
diff --git a/xdiff-interface.c b/xdiff-interface.c
index be448a0..c999469 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -69,36 +69,22 @@ static int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
for (i = 0; i < nbuf; i++) {
if (mb[i].ptr[mb[i].size-1] != '\n') {
/* Incomplete line */
- priv->remainder = xrealloc(priv->remainder,
- priv->remainder_size +
- mb[i].size);
- memcpy(priv->remainder + priv->remainder_size,
- mb[i].ptr, mb[i].size);
- priv->remainder_size += mb[i].size;
+ strbuf_add(&priv->remainder, mb[i].ptr, mb[i].size);
continue;
}
/* we have a complete line */
- if (!priv->remainder) {
+ if (!priv->remainder.len) {
consume_one(priv, mb[i].ptr, mb[i].size);
continue;
}
- priv->remainder = xrealloc(priv->remainder,
- priv->remainder_size +
- mb[i].size);
- memcpy(priv->remainder + priv->remainder_size,
- mb[i].ptr, mb[i].size);
- consume_one(priv, priv->remainder,
- priv->remainder_size + mb[i].size);
- free(priv->remainder);
- priv->remainder = NULL;
- priv->remainder_size = 0;
+ strbuf_add(&priv->remainder, mb[i].ptr, mb[i].size);
+ consume_one(priv, priv->remainder.buf, priv->remainder.len);
+ strbuf_reset(&priv->remainder);
}
- if (priv->remainder) {
- consume_one(priv, priv->remainder, priv->remainder_size);
- free(priv->remainder);
- priv->remainder = NULL;
- priv->remainder_size = 0;
+ if (priv->remainder.len) {
+ consume_one(priv, priv->remainder.buf, priv->remainder.len);
+ strbuf_reset(&priv->remainder);
}
return 0;
}
@@ -148,7 +134,9 @@ int xdi_diff_outf(mmfile_t *mf1, mmfile_t *mf2,
int ret;
xecb->outf = xdiff_outf;
xecb->priv = state;
+ strbuf_init(&state->remainder, 0);
ret = xdl_diff(mf1, mf2, xpp, xecfg, xecb);
+ strbuf_release(&state->remainder);
return ret;
}
diff --git a/xdiff-interface.h b/xdiff-interface.h
index 6f3b361..f6a1ec2 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -2,6 +2,7 @@
#define XDIFF_INTERFACE_H
#include "xdiff/xdiff.h"
+#include "strbuf.h"
struct xdiff_emit_state;
@@ -9,8 +10,7 @@ typedef void (*xdiff_emit_consume_fn)(void *, char *, unsigned long);
struct xdiff_emit_state {
xdiff_emit_consume_fn consume;
- char *remainder;
- unsigned long remainder_size;
+ struct strbuf remainder;
};
int xdi_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb);
--
1.5.6.1
next prev parent reply other threads:[~2008-08-14 5:14 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-13 7:05 [PATCH 1/2] Make xdiff_outf_{init,release} interface Brian Downing
2008-08-14 0:46 ` Junio C Hamano
2008-08-14 2:06 ` Brian Downing
2008-08-14 2:13 ` Junio C Hamano
2008-08-14 5:13 ` [PATCHv2 1/2] Make xdi_diff_outf interface for running xdiff_outf diffs Brian Downing
2008-08-14 5:13 ` Brian Downing [this message]
2008-08-14 5:31 ` Brian Downing
2008-08-14 5:36 ` [PATCHv3 " Brian Downing
2008-08-14 5:36 ` [PATCHv3 2/2] Use strbuf for struct xdiff_emit_state's remainder Brian Downing
2008-08-14 6:18 ` [PATCHv3 1/2] Make xdi_diff_outf interface for running xdiff_outf diffs Junio C Hamano
2008-08-14 6:34 ` Brian Downing
2008-08-21 3:37 ` Brian Downing
2008-08-21 5:24 ` Junio C Hamano
2008-08-21 6:29 ` Brian Downing
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=1218690802-30536-2-git-send-email-bdowning@lavos.net \
--to=bdowning@lavos.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).