* [PATCH] 3% tighter packs for free
@ 2006-03-18 3:45 Nicolas Pitre
2006-03-18 7:21 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Pitre @ 2006-03-18 3:45 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This patch makes for 3.4% smaller pack with the git repository, and
a bit more than 3% smaller pack with the kernel repository.
And so with _no_ measurable CPU difference.
Signed-off-by: Nicolas Pitre <nico@cam.org>
---
diff --git a/diff-delta.c b/diff-delta.c
index aaee7be..1188b31 100644
--- a/diff-delta.c
+++ b/diff-delta.c
@@ -136,7 +136,8 @@ void *diff_delta(void *from_buf, unsigne
unsigned long *delta_size,
unsigned long max_size)
{
- unsigned int i, outpos, outsize, inscnt, hash_shift;
+ unsigned int i, outpos, outsize, hash_shift;
+ int inscnt;
const unsigned char *ref_data, *ref_top, *data, *top;
unsigned char *out;
struct index *entry, **hash;
@@ -222,6 +223,20 @@ void *diff_delta(void *from_buf, unsigne
unsigned char *op;
if (inscnt) {
+ while (moff && ref_data[moff-1] == data[-1]) {
+ if (msize == 0x10000)
+ break;
+ /* we can match one byte back */
+ msize++;
+ moff--;
+ data--;
+ outpos--;
+ if (--inscnt)
+ continue;
+ outpos--; /* remove count slot */
+ inscnt--; /* make it -1 */
+ break;
+ }
out[outpos - inscnt - 1] = inscnt;
inscnt = 0;
}
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] 3% tighter packs for free
2006-03-18 3:45 [PATCH] 3% tighter packs for free Nicolas Pitre
@ 2006-03-18 7:21 ` Junio C Hamano
2006-03-18 18:23 ` Nicolas Pitre
0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2006-03-18 7:21 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: git
Nicolas Pitre <nico@cam.org> writes:
> if (inscnt) {
> + while (moff && ref_data[moff-1] == data[-1]) {
> + if (msize == 0x10000)
> + break;
> + /* we can match one byte back */
> ...
> + break;
> + }
> out[outpos - inscnt - 1] = inscnt;
Once you make it into a patch form, it is plainly obvious that
this is a good optimization. Since our BLK_SIZE is 16 bytes,
you are grabbing up to 15 more bytes (on average 8 more bytes or
so) for every match after a partially modified block.
Very nice. I wonder if a larger BLK_SIZE (say 32 bytes) would
give us faster packing without losing much compression if we use
this idea.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] 3% tighter packs for free
2006-03-18 7:21 ` Junio C Hamano
@ 2006-03-18 18:23 ` Nicolas Pitre
2006-03-18 19:24 ` Junio C Hamano
0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Pitre @ 2006-03-18 18:23 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
On Fri, 17 Mar 2006, Junio C Hamano wrote:
> Once you make it into a patch form, it is plainly obvious that
> this is a good optimization. Since our BLK_SIZE is 16 bytes,
> you are grabbing up to 15 more bytes (on average 8 more bytes or
> so) for every match after a partially modified block.
>
> Very nice. I wonder if a larger BLK_SIZE (say 32 bytes) would
> give us faster packing without losing much compression if we use
> this idea.
Tried that long ago. As BLK_SIZE is increased the adler32 cost, which
has to be computed for every offset in the target buffer, increases
accordingly. So you end up with both worse compression and more CPU
usage.
Nicolas
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] 3% tighter packs for free
2006-03-18 18:23 ` Nicolas Pitre
@ 2006-03-18 19:24 ` Junio C Hamano
0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2006-03-18 19:24 UTC (permalink / raw)
To: Nicolas Pitre; +Cc: git
Nicolas Pitre <nico@cam.org> writes:
> Tried that long ago. As BLK_SIZE is increased the adler32 cost, which
> has to be computed for every offset in the target buffer, increases
> accordingly. So you end up with both worse compression and more CPU
> usage.
Ah, I was not paying enough attention. I did not realize
destination scanning was done for every byte.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2006-03-18 19:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-18 3:45 [PATCH] 3% tighter packs for free Nicolas Pitre
2006-03-18 7:21 ` Junio C Hamano
2006-03-18 18:23 ` Nicolas Pitre
2006-03-18 19:24 ` Junio C Hamano
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox