threads / patch / 3285

patchdelta micro optimization

Subject: [PATCH] delta micro optimization

## tl;dr

3 messages between Feb 10, 2006 and Feb 10, 2006. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Nicolas Pitre· Feb 10, 2006, 18:42 UTC · lore

My kernel work habit made me look at the generated assembly for the delta code, and one obvious albeit small improvement is this patch.

Signed-off-by: Nicolas Pitre <nico@cam.org>
---
Show changes to delta.h +5 −5
diff --git a/delta.h b/delta.h
index 31d1820..a15350d 100644
--- a/delta.h
+++ b/delta.h
@@ -19,14 +19,14 @@ extern void *patch_delta(void *src_buf, 
 static inline unsigned long get_delta_hdr_size(const unsigned char **datap)
 {
 	const unsigned char *data = *datap;
-	unsigned char cmd = *data++;
-	unsigned long size = cmd & ~0x80;
-	int i = 7;
-	while (cmd & 0x80) {
+	unsigned char cmd;
+	unsigned long size = 0;
+	int i = 0;
+	do {
 		cmd = *data++;
 		size |= (cmd & ~0x80) << i;
 		i += 7;
-	}
+	} while (cmd & 0x80);
 	*datap = data;
 	return size;
 }
Junio C Hamano· Feb 10, 2006, 20:00 UTC · re: Nicolas Pitre · lore

Re: [PATCH] delta micro optimization

That looks obviously correct but it really is micro. Have you benched it? On which architectures? Does it help everywhere or register starved ones benefit more than others?

Nicolas Pitre· Feb 10, 2006, 20:38 UTC · re: Junio C Hamano · lore

Re: [PATCH] delta micro optimization

On Fri, 10 Feb 2006, Junio C Hamano wrote:
> That looks obviously correct but it really is micro.  Have you
> benched it?  On which architectures?  Does it help everywhere or
> register starved ones benefit more than others?

I doubt the performance difference would be measurable on i386 although the code is a bit smaller.

On ARM it causes a code reduction of 12.5% in count-delta.o.
Nicolas

← back to recent threads