[Fwd: libpng shared memory patch]



Andrea Bedini has started kicking ass!  This constifies a bunch of
things in libpng.

  Federico
--- Begin Message ---
Hi,
in response to your
http://primates.ximian.com/~federico/news-2006-04.html#footprint-private-dirty

thank you for writing a such a simple and understandable explanation
of sharing mechanism. I piked up a small library like libpng a I tried
to analyze its exposed structs, looking for some const to place. I got
one third reduction of memory footprint, but I think we can reduce it
further. Here are the details and a patch.

libpng version 1.2.8rel-5 from dapper

before:

$ objdump -x /usr/lib/libpng.so  | grep data
  11 .rodata       00002a00  00021a30  00021a30  00021a30  2**3
 18 .data         00000348  00034cd0  00034cd0  00024cd0  2**2
  20 .sdata        000000b0  0003502c  0003502c  0002502c  2**2

0x348+0xb0=0x3F8=1016 bytes

$ python memstats.py | grep libpng
private: /usr/lib/libpng12.so.0.1.2.8: 168 KB (spread among 84 mappings)
shared: /usr/lib/libpng12.so.0.1.2.8: 16 KB (spread among 84 mappings)

(with 107 processes around)

after:

$ objdump -x libpng12.so| grep .data | head
  11 .rodata       00002d40  00021a30  00021a30  00021a30  2**3
 18 .data         00000008  0003589c  0003589c  0002589c  2**2
  20 .sdata        000000b0  000358b8  000358b8  000258b8  2**2

0x340 = 832 bytes moved from .data to .rodata; maybe another 100 bytes
can be moved.

$ python memstats.py | grep libpng
private: /usr/lib/libpng12.so.0.1.2.8: 100 KB (spread among 81 mappings)
shared: /usr/lib/libpng12.so.0.1.2.8: 8 KB (spread among 81 mappings)

(with 100 processes around)

size of .data + .sdata has been reduced from about 1Kb to about 0.2Kb
this means 80%, why the final result if just 30% ? maybe a lot of
processes use the 20% that remains in .sdata ?

Feel free for forward this mail to everyone you like; I don't know
which is the right place, so I send this to you.

Thank you again for your effort in free software.
Andrea

--
Andrea Bedini <andrea bedini gmail com>
Common subdirectories: libpng-1.2.8rel/contrib and libpng-1.2.8rel-patched/contrib
Common subdirectories: libpng-1.2.8rel/debian and libpng-1.2.8rel-patched/debian
diff -u libpng-1.2.8rel/pngerror.c libpng-1.2.8rel-patched/pngerror.c
--- libpng-1.2.8rel/pngerror.c	2004-12-03 01:14:25.000000000 +0100
+++ libpng-1.2.8rel-patched/pngerror.c	2006-04-21 22:39:19.000000000 +0200
@@ -104,7 +104,7 @@
  * if the character is invalid.
  */
 #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
-static PNG_CONST char png_digit[16] = {
+const static PNG_CONST char png_digit[16] = {
    '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
    'A', 'B', 'C', 'D', 'E', 'F'
 };
diff -u libpng-1.2.8rel/pnggccrd.c libpng-1.2.8rel-patched/pnggccrd.c
--- libpng-1.2.8rel/pnggccrd.c	2004-12-03 01:14:25.000000000 +0100
+++ libpng-1.2.8rel-patched/pnggccrd.c	2006-04-21 22:41:35.000000000 +0200
@@ -249,9 +249,9 @@
 int PNGAPI png_mmx_support(void);
 
 #ifdef PNG_USE_LOCAL_ARRAYS
-static const int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
-static const int FARDATA png_pass_inc[7]   = {8, 8, 4, 4, 2, 2, 1};
-static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
+const static const int FARDATA png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
+const static const int FARDATA png_pass_inc[7]   = {8, 8, 4, 4, 2, 2, 1};
+const static const int FARDATA png_pass_width[7] = {8, 4, 4, 2, 2, 1, 1};
 #endif
 
 #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
@@ -309,30 +309,30 @@
 static int _unmask;
 #endif
 
-static unsigned long long _mask8_0  = 0x0102040810204080LL;
+const static unsigned long long _mask8_0  = 0x0102040810204080LL;
 
-static unsigned long long _mask16_1 = 0x0101020204040808LL;
-static unsigned long long _mask16_0 = 0x1010202040408080LL;
+const static unsigned long long _mask16_1 = 0x0101020204040808LL;
+const static unsigned long long _mask16_0 = 0x1010202040408080LL;
 
-static unsigned long long _mask24_2 = 0x0101010202020404LL;
-static unsigned long long _mask24_1 = 0x0408080810101020LL;
-static unsigned long long _mask24_0 = 0x2020404040808080LL;
-
-static unsigned long long _mask32_3 = 0x0101010102020202LL;
-static unsigned long long _mask32_2 = 0x0404040408080808LL;
-static unsigned long long _mask32_1 = 0x1010101020202020LL;
-static unsigned long long _mask32_0 = 0x4040404080808080LL;
-
-static unsigned long long _mask48_5 = 0x0101010101010202LL;
-static unsigned long long _mask48_4 = 0x0202020204040404LL;
-static unsigned long long _mask48_3 = 0x0404080808080808LL;
-static unsigned long long _mask48_2 = 0x1010101010102020LL;
-static unsigned long long _mask48_1 = 0x2020202040404040LL;
-static unsigned long long _mask48_0 = 0x4040808080808080LL;
-
-static unsigned long long _const4   = 0x0000000000FFFFFFLL;
-//static unsigned long long _const5 = 0x000000FFFFFF0000LL;     // NOT USED
-static unsigned long long _const6   = 0x00000000000000FFLL;
+const static unsigned long long _mask24_2 = 0x0101010202020404LL;
+const static unsigned long long _mask24_1 = 0x0408080810101020LL;
+const static unsigned long long _mask24_0 = 0x2020404040808080LL;
+
+const static unsigned long long _mask32_3 = 0x0101010102020202LL;
+const static unsigned long long _mask32_2 = 0x0404040408080808LL;
+const static unsigned long long _mask32_1 = 0x1010101020202020LL;
+const static unsigned long long _mask32_0 = 0x4040404080808080LL;
+
+const static unsigned long long _mask48_5 = 0x0101010101010202LL;
+const static unsigned long long _mask48_4 = 0x0202020204040404LL;
+const static unsigned long long _mask48_3 = 0x0404080808080808LL;
+const static unsigned long long _mask48_2 = 0x1010101010102020LL;
+const static unsigned long long _mask48_1 = 0x2020202040404040LL;
+const static unsigned long long _mask48_0 = 0x4040808080808080LL;
+
+const static unsigned long long _const4   = 0x0000000000FFFFFFLL;
+//const static unsigned long long _const5 = 0x000000FFFFFF0000LL;     // NOT USED
+const static unsigned long long _const6   = 0x00000000000000FFLL;
 
 // These are used in the row-filter routines and should/would be local
 //  variables if not for gcc addressing limitations.
diff -u libpng-1.2.8rel/pngrtran.c libpng-1.2.8rel-patched/pngrtran.c
--- libpng-1.2.8rel/pngrtran.c	2004-12-03 01:14:25.000000000 +0100
+++ libpng-1.2.8rel-patched/pngrtran.c	2006-04-21 22:20:50.000000000 +0200
@@ -3894,7 +3894,7 @@
 
 #ifdef PNG_FLOATING_POINT_SUPPORTED
 #if defined(PNG_READ_GAMMA_SUPPORTED)
-static int png_gamma_shift[] =
+const static int png_gamma_shift[] =
    {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0};
 
 /* We build the 8- or 16-bit gamma tables here.  Note that for 16-bit
diff -u libpng-1.2.8rel/pngrutil.c libpng-1.2.8rel-patched/pngrutil.c
--- libpng-1.2.8rel/pngrutil.c	2004-12-03 01:14:25.000000000 +0100
+++ libpng-1.2.8rel-patched/pngrutil.c	2006-04-21 22:42:20.000000000 +0200
@@ -177,7 +177,7 @@
                               png_charp chunkdata, png_size_t chunklength,
                               png_size_t prefix_size, png_size_t *newlength)
 {
-   static char msg[] = "Error decoding compressed text";
+   const static char msg[] = "Error decoding compressed text";
    png_charp text;
    png_size_t text_size;
 
diff -u libpng-1.2.8rel/pngtrans.c libpng-1.2.8rel-patched/pngtrans.c
--- libpng-1.2.8rel/pngtrans.c	2004-12-03 01:14:26.000000000 +0100
+++ libpng-1.2.8rel-patched/pngtrans.c	2006-04-21 22:14:52.000000000 +0200
@@ -241,7 +241,7 @@
 #endif
 
 #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
-static png_byte onebppswaptable[256] = {
+const static png_byte onebppswaptable[256] = {
    0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
    0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
    0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
@@ -276,7 +276,7 @@
    0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
 };
 
-static png_byte twobppswaptable[256] = {
+const static png_byte twobppswaptable[256] = {
    0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
    0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
    0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
@@ -311,7 +311,7 @@
    0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
 };
 
-static png_byte fourbppswaptable[256] = {
+const static png_byte fourbppswaptable[256] = {
    0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
    0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
    0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
@@ -362,11 +362,11 @@
       end = row + row_info->rowbytes;
 
       if (row_info->bit_depth == 1)
-         table = onebppswaptable;
+         table = (png_bytep) onebppswaptable;
       else if (row_info->bit_depth == 2)
-         table = twobppswaptable;
+         table = (png_bytep) twobppswaptable;
       else if (row_info->bit_depth == 4)
-         table = fourbppswaptable;
+         table = (png_bytep) fourbppswaptable;
       else
          return;
 
Common subdirectories: libpng-1.2.8rel/projects and libpng-1.2.8rel-patched/projects
Common subdirectories: libpng-1.2.8rel/scripts and libpng-1.2.8rel-patched/scripts





--- End Message ---


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