Re: cleaner/better zlib sources?
- From
- Davide Libenzi <davidel@xmailserver.org>
- Date
- Mar 16, 2007, 01:33 UTC
- Message-ID
- <Pine.LNX.4.64.0703151807010.4998@alien.or.mcafeemobile.com>
- In-Reply-To
- <Pine.LNX.4.64.0703151747110.3816@woody.linux-foundation.org>
On Thu, 15 Mar 2007, Linus Torvalds wrote:
Show 23 quoted lines
>
> 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