Linked by Thom Holwerda on Sat 28th Jun 2008 22:09 UTC, submitted by diegocg
X11, Window Managers "Maybe I'm just naive, but designing a graphics API such that all image data had to be sent over a socket to another process every time the image needed to be drawn seems like complete idiocy. Unfortunately, that is precisely what the X Window System forces a program to do, and exactly what Cairo does when drawing images in Linux - a full copy of the image data, send to another process, no less, every time it is drawn. One would think there would be some room for improvement. Unsurprisingly, others felt the same way about X, and decided to write an extension, Xlib Shm or XShm for short, that allows images to placed in a shared memory segment from which the X server reads which allows the program to avoid the memory copy. GTK already makes use of the XShm extension, and it seems like a good idea to see if Gecko couldn't do the same."
Thread beginning with comment 320540
To view parent comment, click here.
To read all comments associated with this story, please click here.
RE: Exaggerating
by rayiner on Sun 29th Jun 2008 01:50 UTC in reply to "Exaggerating"
rayiner
Member since:
2005-07-06

This is a key point!

The "idiocy" comment in the original posting was way off-base. The XImage system actually makes a ton of sense. In most apps, you're drawing the same images over and over again (sprites, chrome). Its not a big deal to transfer them to the X server the first time they're drawn. In a web-browser context, you're drawing different images all the time, but what do you think is the bottleneck, copying the image to the X server, or downloading them from the internet?

Where XShm helps is when you dynamically generate images for each frame, and as such are constantly uploading new images to the Xserver to draw. However, even in that case, it is unlikely to provide a huge speedup, since the overall time is probably dominated by creating the image, not copying it to the X server.

Reply Parent Score: 8

RE[2]: Exaggerating
by diegocg on Sun 29th Jun 2008 09:02 in reply to "RE: Exaggerating"
diegocg Member since:
2005-07-08

There's an additional big problem with sockets: Once you send the image to the server, the client can't "share" it, because it's living in the server's address space. So you have a copy of the image on the server AND exactly the same copy of the image on the client. The image is effectively using 2x its size in the memory.

The "right fix" for this stupid waste of resources is to free() the image on the client. With shared memory, you can SHARE the image's memory between the client and the process.

That's how things should work on a sane local graphic setup, but X is far from being "sane". Yes, X.org IS efficient and comparable to other systems, but only because people have spent a lot of time workarounding the stupid things it does so that at the end in local systems it works like other sane systems.

That's the funny thing: X is supposed to be "network transparent", but then the server and the client need to DETECT if they're in "local mode", or if such extension is enabled or not, and make SPECIAL MODIFICATIONS to the code paths so that it works right. There's no "transparency" anymore, as applications (toolkits) need to be aware of such low-level graphic details and code different paths according to the results. It has been needed to create many X extensions, it has been needed to MODIFY applications to use those extensions...oh my god, it's just not fun even to think about it. And to think that backwards compatibility is all that was stopping people from doing it right...

Edited 2008-06-29 09:20 UTC

Reply Parent Score: 5

RE[3]: Exaggerating
by FooBarWidget on Sun 29th Jun 2008 10:20 in reply to "RE[2]: Exaggerating"
FooBarWidget Member since:
2005-11-11

That's how things should work on a sane local graphic setup, but X is far from being "sane". Yes, X.org IS efficient and comparable to other systems, but only because people have spent a lot of time workarounding the stupid things it does so that at the end in local systems it works like other sane systems.


How is any of this "stupid"? Isn't that exactly how most software is supposed to be engineered? What do you expect from them? That shared memory somehow magically works over the network? What kind of answer would satisfy you?


That's the funny thing: X is supposed to be "network transparent", but then the server and the client need to DETECT if they're in "local mode", or if such extension is enabled or not, and make SPECIAL MODIFICATIONS to the code paths so that it works right.


No they don't. "Transparent" means that you don't *have* to do that. Even if you don't use the special modifications, things will still work. It's just that if you do use the special modifications, then things will be more efficient.

Really, what more do you want? It seems that no matter what solution is given, you will never be satisfied until X doesn't work over the network at all. While that may be less "stupid" in your eyes, it'll actually be a step backwards, because then all your apps are still working on the same speed, *and* they don't work on the network anymore.

Reply Parent Score: 11

RE[3]: Exaggerating
by renox on Sun 29th Jun 2008 10:30 in reply to "RE[2]: Exaggerating"
renox Member since:
2005-07-06

Note that sharing the image between the client and the server is not always the right thing to do as setting up shared memory is costly.

So the wise thing to do is to copy small images and use shared memory only for big one.

As for you're rant against X, I'd say that 'standard X' is network transparent, but when you want to use local optimisations, then it isn't network transparent anymore, which makes sense.
That's why we have toolkits which hide this.

Reply Parent Score: 3

RE[3]: Exaggerating
by fernandotcl on Wed 2nd Jul 2008 03:58 in reply to "RE[2]: Exaggerating"
fernandotcl Member since:
2007-08-12

There's an additional big problem with sockets: Once you send the image to the server, the client can't "share" it, because it's living in the server's address space. So you have a copy of the image on the server AND exactly the same copy of the image on the client. The image is effectively using 2x its size in the memory. The "right fix" for this stupid waste of resources is to free() the image on the client. With shared memory, you can SHARE the image's memory between the client and the process.

The client can't share it? Wtf? Once you send it, it's gone? Have you EVER dealt with sockets at all?

It's not a big deal having it in memory twice. That certainly is not a bottleneck for 99% of all X apps out there nowadays.

The "right fix"... OMG...

Reply Parent Score: 1