[Xcb] [PATCH] Reduce memory footprint of xcb-atom

Tilman Sauerbeck tilman at code-monkey.de
Fri May 11 09:16:25 PDT 2007


Hi,
the attached patch (which goes on top of the patch for #10877) reduces
the memory footprint of libxcb-atom.so, and the number of relocations
that have to be performed on load.

It replaces the char*-array that holds the atom names with one giant
string, and another array that holds the offsets of the atom names
inside that string.

Since the code is generated via m4, there's no additional maintenance
cost in this.

Some numbers:
before:

   atom/.libs/libxcb-atom.so: 73 relocations [...]

   text	   data	    bss	    dec	    hex	filename
   9587	    588	    132	  10307	   2843	atom/.libs/libxcb-atom.so

after:

   atom/.libs/libxcb-atom.so: 5 relocations

   text	   data	    bss	    dec	    hex	filename
   9183	    316	    132	   9631	   259f	atom/.libs/libxcb-atom.so

Regards,
Tilman

-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
-------------- next part --------------
diff --git a/atom/atoms.gperf.m4 b/atom/atoms.gperf.m4
index 9554972..f40b9b0 100644
--- a/atom/atoms.gperf.m4
+++ b/atom/atoms.gperf.m4
@@ -22,8 +22,19 @@ define(`COUNT', 0)dnl
 define(`DO', `$1,define(`COUNT', incr(COUNT))COUNT')dnl
 include(atomlist.m4)`'dnl
 %%
-static const char *const atom_names[] = {
-define(`DO', `	"$1",')dnl
+
+#define MAX_ATOM_NO \
+	COUNT
+
+static const char atom_names[] =
+define(`OFFSET', 0)dnl
+define(`DO', `	"$1\0"')dnl
+include(atomlist.m4)`'dnl
+;
+
+static const uint16_t atom_name_offsets[] = {
+define(`OFFSET', 0)dnl
+define(`DO', `	OFFSET,define(`OFFSET', eval(OFFSET+1+len($1)))')dnl
 include(atomlist.m4)`'dnl
 };
 
@@ -76,9 +87,9 @@ xcb_atom_t intern_atom_fast_reply(xcb_connection_t *c, intern_atom_fast_cookie_t
 
 const char *get_atom_name_predefined(xcb_atom_t atom)
 {
-	if(atom <= 0 || atom > (sizeof(atom_names) / sizeof(*atom_names)))
+	if(atom <= 0 || atom > COUNT)
 		return 0;
-	return atom_names[atom - 1];
+	return atom_names + atom_name_offsets[atom - 1];
 }
 
 int get_atom_name(xcb_connection_t *c, xcb_atom_t atom, const char **namep, int *lengthp)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/xcb/attachments/20070511/7aec3f94/attachment.pgp 


More information about the Xcb mailing list