I'm trying to work on XCB this week. And today I've started to accomplish the second step of a long term goal: making an X11 only library using XCB as its primary interface instead of Xlib.
Last year, I had extended the API of startup-notification to support XCB as a back-end. This had been made possible by factorizing some code, duplicating the X11 code and translating it into equivalent XCB.
Today, I've accomplished the second step, being dropping the Xlib code inside startup-notification to keep only the XCB one.
For this, I used the x11-xcb library, which is available when Xlib is compiled with XCB as its transport, which is nowadays the standard.
This library provides the function XGetXCBConnection, which can convert a Display pointer to a xcb_connection_t pointer. Consequently, it's now possible to write and execute XCB based code and being compatible with Xlib.
I've made some benchmark of my work for the occasion, in order to measure what the gain is.
The first table described 1000 launches of a fake application (a modified version of the startup-notification test suite actually). The X server is local (the latency is very minimal then). The gain is computed between the same back-end type for the total time. Full XCB is the "version" I'm working on.
|Version - Back-end||User time (seconds)||Kernel time (seconds)||Total time (seconds)||Gain|
|0.10 - libx11||3.20||7.42||12.989||-|
|0.10 - libxcb||2.76||7.36||12.414||-|
|Full XCB - libx11||2.74||7.50||12.380||4.6 %|
|Full XCB - libxcb||2.72||7.16||12.037||3.0 %|
The user time and kernel time are provided but are not really interesting. XCB does not offers a big gain in CPU execution time, but is more about latency. Anyhow, there's always a gain with XCB.
This second table describe the same test but running only 100 times over a slow network.
|Version - Back-end||Total time (seconds)||Gain|
|0.10 - libx11||76||-|
|0.10 - libxcb||35||-|
|Full XCB - libx11||72||5.2 %|
|Full XCB - libxcb||33||5.7%|
The gain is relatively small, about 5 %. But anyhow, there's still a gain. Note that the difference between the execution time of the same test written in XCB and Xlib is just huge. I've tried to optimize the Xlib test, but I did not manage to win more seconds.
In conclusion, considering that startup-notification is only used when an application launches another application, the perceivable gain might be even smaller. But anyhow, I think it's worth it.