git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: cleaner/better zlib sources?

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Mar 17, 2007, 00:01 UTC
Message-ID
<Pine.LNX.4.64.0703161636520.3910@woody.linux-foundation.org>
In-Reply-To
<Pine.LNX.4.64.0703161216510.13732@alien.or.mcafeemobile.com>
On Fri, 16 Mar 2007, Davide Libenzi wrote:
>
> I cannot measure any sensible difference between the two.

I'm using your previous patch (is it the same?) along with the additional patch appended.

And yes, it's not hugely faster, but I seem to see *some* difference: this is the real-time of ten runs of

	time git log drivers/usb/ > /dev/null
Before:
	0m2.673s
	0m2.476s
	0m2.603s
	0m2.576s
	0m2.625s
	0m2.628s
	0m2.493s
	0m2.696s
	0m2.525s
	0m2.575s
After:
	0m2.639s
	0m2.519s
	0m2.454s
	0m2.604s
	0m2.499s
	0m2.497s
	0m2.506s
	0m2.394s
	0m2.409s
	0m2.562s

ie after I actually get under 2.4s once, and under 2.5s most of the time, while before it was under 2.5s just twice, and mostly in the 2.6s..

(I did end up adding the "-g", but I trust that doesn't make things *faster*. Generally gcc is good at not actually changing code generation based on -g)

But yeah, not very impressive changes. We're talking *maybe* 0.1s out of 2.5, so potentially about 4% of total time but more likely about 2-3%, and it's clearly mostly in the noise. And inflate() is still at 16%, and inflate_fast obviously got no faster.

The nice part is that the instruction-level profile for inflate() got more interesting. Instead of clearly peaking at the silly indirect jump, the peak now seems to be a specific path through the thing. I've not decoded it fully yet, but it seems to be mostly the LEN/LIT cases:

 file inflate.c, line 942.
 file inflate.c, line 942.
 file inflate.c, line 949.
 file inflate.c, line 949.
 file inflate.c, line 949.
 file inflate.c, line 949.
 file inflate.c, line 949.
 file inflate.c, line 950.
 file inflate.c, line 950.
 file inflate.c, line 951.
 file inflate.c, line 951.
 file inflate.c, line 951.
 file inflate.c, line 951.
 file inflate.c, line 951.
 file inflate.c, line 949.
 file inflate.c, line 949.
 file inflate.c, line 950.
 file inflate.c, line 950.
 file inflate.c, line 953.
 file inflate.c, line 953.
 file inflate.c, line 953.
 file inflate.c, line 969.
 file inflate.c, line 1058.
 file inflate.c, line 1059.
 file inflate.c, line 1061.
 file inflate.c, line 884.
 file inflate.c, line 963.
 file inflate.c, line 964.

(those are the line numbers *after* applying my patch for where the hotpoints are: the same line-number showing up multiple times is just because several hot instructions came from there and got spread out)

			Linus
---
diff --git a/Makefile b/Makefile
index 2fd6e45..d8e9ff4 100644
--- a/Makefile
+++ b/Makefile
@@ -18,7 +18,7 @@
 
 CC=cc
 
-CFLAGS=-O
+CFLAGS=-O -g
 #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
 #CFLAGS=-g -DDEBUG
 #CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
diff --git a/inflate.c b/inflate.c
index 190c642..3d41d6f 100644
--- a/inflate.c
+++ b/inflate.c
@@ -568,7 +568,7 @@ int flush;
     unsigned char FAR *next;    /* next input */
     unsigned char FAR *put;     /* next output */
     unsigned have, left;        /* available input and output */
-    unsigned long hold;         /* bit buffer */
+    unsigned long hold, old_hold;/* bit buffer */
     unsigned bits;              /* bits in bit buffer */
     unsigned in, out;           /* save starting available input and output */
     unsigned copy;              /* number of stored or match bytes to copy */
@@ -631,8 +631,11 @@ int flush;
             state->dmax = 1U << len;
             Tracev((stderr, "inflate:   zlib header ok\n"));
             strm->adler = state->check = adler32(0L, Z_NULL, 0);
-            state->mode = hold & 0x200 ? DICTID : TYPE;
+            old_hold = hold;
             INITBITS();
+            if (old_hold & 0x200)
+            	STATE_CHANGE(DICTID);
+            STATE_CHANGE(TYPE);
             break;
 #ifdef GUNZIP
         CASE_DECL(FLAGS)
@@ -817,7 +820,7 @@ int flush;
             state->mode = COPY;
         CASE_DECL(COPY)
             copy = state->length;
-            if (copy) {
+            while (copy) {
                 if (copy > have) copy = have;
                 if (copy > left) copy = left;
                 if (copy == 0) goto inf_leave;
@@ -826,8 +829,8 @@ int flush;
                 next += copy;
                 left -= copy;
                 put += copy;
-                state->length -= copy;
-                break;
+                copy = state->length - copy;
+                state->length = copy;
             }
             Tracev((stderr, "inflate:       stored end\n"));
 	    STATE_CHANGE(TYPE);
Previous: Davide LibenziNext: Linus Torvalds
Message 14 of 79 in “cleaner/better zlib sources?”
  1. Linus TorvaldsMar 16, 2007
  2. Shawn O. PearceMar 16, 2007
  3. Jeff GarzikMar 16, 2007
  4. Matt MackallMar 16, 2007
  5. Linus TorvaldsMar 16, 2007
  6. Linus TorvaldsMar 16, 2007
  7. Davide LibenziMar 16, 2007
  8. Linus TorvaldsMar 16, 2007
  9. Davide LibenziMar 16, 2007
  10. Linus TorvaldsMar 16, 2007
  11. Davide LibenziMar 16, 2007
  12. Linus TorvaldsMar 16, 2007
  13. Davide LibenziMar 16, 2007
  14. Linus TorvaldsMar 17, 2007
  15. Linus TorvaldsMar 17, 2007
  16. Nicolas PitreMar 17, 2007
  17. Shawn O. PearceMar 17, 2007
  18. Linus TorvaldsMar 17, 2007
  19. Linus TorvaldsMar 17, 2007
  20. 1/2 Make trivial wrapper functions around delta base generation and freeingLinus Torvalds, Mar 17, 2007
  21. 2/2 Implement a simple delta_base cacheLinus Torvalds, Mar 17, 2007
  22. Linus TorvaldsMar 17, 2007
  23. Junio C HamanoMar 17, 2007
  24. Linus TorvaldsMar 17, 2007
  25. Linus TorvaldsMar 17, 2007
  26. Nicolas PitreMar 18, 2007
  27. Junio C HamanoMar 18, 2007
  28. Junio C HamanoMar 17, 2007
  29. Linus TorvaldsMar 17, 2007
  30. Jon SmirlMar 17, 2007
  31. Morten WelinderMar 18, 2007
  32. Linus TorvaldsMar 18, 2007
  33. Nicolas PitreMar 18, 2007
  34. Linus TorvaldsMar 18, 2007
  35. Nicolas PitreMar 18, 2007
  36. Linus TorvaldsMar 18, 2007
  37. Nicolas PitreMar 18, 2007
  38. Linus TorvaldsMar 18, 2007
  39. Julian PhillipsMar 18, 2007
  40. Linus TorvaldsMar 18, 2007
  41. Robin RosenbergMar 18, 2007
  42. Linus TorvaldsMar 18, 2007
  43. Robin RosenbergMar 18, 2007
  44. Shawn O. PearceMar 18, 2007
  45. David BrodskyMar 19, 2007
  46. Robin RosenbergMar 20, 2007
  47. David BrodskyMar 20, 2007
  48. Linus TorvaldsMar 21, 2007
  49. Nicolas PitreMar 21, 2007
  50. 3/2 Avoid unnecessary strlen() callsLinus Torvalds, Mar 18, 2007
  51. Junio C HamanoMar 18, 2007
  52. Linus TorvaldsMar 18, 2007
  53. Linus TorvaldsMar 18, 2007
  54. Shawn O. PearceMar 18, 2007
  55. Linus TorvaldsMar 18, 2007
  56. Johannes SchindelinMar 20, 2007
  57. Shawn O. PearceMar 20, 2007
  58. Shawn O. PearceMar 20, 2007
  59. Linus TorvaldsMar 20, 2007
  60. Shawn O. PearceMar 20, 2007
  61. Linus TorvaldsMar 20, 2007
  62. Junio C HamanoMar 20, 2007
  63. Junio C HamanoMar 20, 2007
  64. Linus TorvaldsMar 20, 2007
  65. Shawn O. PearceMar 20, 2007
  66. Linus TorvaldsMar 20, 2007
  67. Linus TorvaldsMar 18, 2007
  68. Avi KivityMar 18, 2007
  69. Linus TorvaldsMar 17, 2007
  70. Jeff GarzikMar 16, 2007
  71. Matt MackallMar 16, 2007
  72. Linus TorvaldsMar 16, 2007
  73. Nicolas PitreMar 16, 2007
  74. Shawn O. PearceMar 16, 2007
  75. Nicolas PitreMar 16, 2007
  76. Linus TorvaldsMar 16, 2007
  77. Nicolas PitreMar 16, 2007
  78. Davide LibenziMar 16, 2007
  79. Davide LibenziMar 16, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.