Re: cleaner/better zlib sources?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, 15 Mar 2007, Linus Torvalds wrote:

> 
> I looked at git profiles yesterday, and some of them are pretty scary. We 
> spend about 50% of the time under some loads in just zlib uncompression, 
> and when I actually looked closer at the zlib sources I can kind of 
> understand why. That thing is horrid.
> 
> The sad part is that it looks like it should be quite possible to make 
> zlib simply just perform better. The profiles seem to say that a lot of 
> the cost is literally in the "inflate()" state machine code (and by that I 
> mean *not* the code itself, but literally in the indirect jump generated 
> by the case-statement).
> 
> Now, on any high-performance CPU, doing state-machines by having
> 
> 	for (;;)
> 		switch (data->state) {
> 			...
> 			data->state = NEW_STATE;
> 			continue;
> 		}
> 
> (which is what zlib seems to be doing) is just about the worst possible 
> way to code things.

A quick hack would be to just define:

#define SWITCH_LBL(n) \
	case n: \
	lbl_##n:

#define STATE_CHANGE(s) \
	state->mode = s; \
	goto lbl_##s;

Then replace all the "state->mode = STATE; break;" into STATE_CHANGE(STATE);
I'm giving it a try as we speak ...




- Davide


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]