Subject: FVWM: Re: Memory Allocations/XDrawSegment

From: Dave Trollope <[email-masked]>
Date: Fri, 19 Apr 2002 21:02:58 -0500

Hi Dominik, all,

A few weeks back you had the following advice for me and I finally got to
taking a look at some things around ReleiveRectangle.

I found that RelieveRectangle and RelieveRectangle2 both call
do_relieve_rectangle. In looking at do_relieve_rectangle I found that
XDrawSegments is called 4 times for two conditions, ShadowGC and RelieveGC. I
have merged the array two reduce the X calls XDrawSegment from 4 to 2 by
sending the data for two requests in one call.

However, before we commit this patch, I'd like it to be tested on some other
systems rather than my own since my knowledge is limited. Can you take a look
at this patch, and apply it on your system and note any irregularities?

Can some others take a look and apply this too? If no-one reports any bugs
within a week I propose we add it in to the repositary.

What do you think?

Thanks
Dave

> Fvwm's speed depends to 90% or more on how the communication with
> the X server is done.  All other effects of calling functions and
> such only add very little to the CPU load.  Once I profiled fvwm
> for ten minutes using gprof, and as far as I remember it did not
> even consume one second of CPU time.  The things that slow it down
> are file I/O and X server communication.

> > libs/Graphics.c - do_relieve_rectangle
> >
> >
>
> Yes, but what is the cost of the malloc?  RelieveRectangle is
> perhaps called 20 times when a window changes focus.  I'd guess on
> average you do not do this more than 5 times per minute, giving a
> total of 6000 calls per hour.  I'd estimate that can easily be
> done by any but the slowest machines in less than the tenth of a
> second.  It is likely that more time could be saved by preventing
> unnecessary calls to RelieveRectangle() in a single place in the
> code since it requires communication over the network.

--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].

---

From: Dave Trollope <[email-masked]>
Date: Fri, 19 Apr 2002 21:04:52 -0500

Hi Dominik, all,

What do you think?

Thanks
Dave

> code since it requires communication over the network.
Index: libs/Graphics.c
===================================================================
RCS file: /home/cvs/fvwm/fvwm/libs/Graphics.c,v
retrieving revision 1.57
diff -u -r1.57 Graphics.c
--- libs/Graphics.c	2002/04/05 09:24:29	1.57
+++ libs/Graphics.c	2002/04/20 01:05:51
@@ -60,7 +60,7 @@
 	GC ReliefGC, GC ShadowGC, int line_width, Bool use_alternate_shading)
 {
 	XSegment* seg;
-	int i;
+	int i,i2;
 	int a = (use_alternate_shading) ? 1 : 0;
 
 	if (w <= 0 || h <= 0)
@@ -72,31 +72,31 @@
 		}
 		return;
 	}
-	seg = (XSegment*)alloca(sizeof(XSegment) * line_width);
+	seg = (XSegment*)alloca((sizeof(XSegment) * line_width) * 2);
 	/* left side, from 0 to the lesser of line_width & just over half w */
 	for (i = 0; (i < line_width) && (i <= w / 2); i++) {
 		seg[i].x1 = x+i; seg[i].y1 = y+i+a;
 		seg[i].x2 = x+i; seg[i].y2 = y+h-i-1+a;
 	}
-	XDrawSegments(dpy, d, ReliefGC, seg, i);
+	i2 = i;
+	/* draw top segments */
+	for (i = 0; (i < line_width) && (i <= h / 2); i++,i2++) {
+		seg[i2].x1 = x+w-i-a; seg[i2].y1 = y+i;
+		seg[i2].x2 = x+i+1-a; seg[i2].y2 = y+i;
+	}
+	XDrawSegments(dpy, d, ReliefGC, seg, i2);
 	/* bottom */
 	for (i = 0; (i < line_width) && (i <= h / 2); i++) {
 		seg[i].x1 = x+i+a;     seg[i].y1 = y+h-i;
 		seg[i].x2 = x+w-i-1+a; seg[i].y2 = y+h-i;
 	}
-	XDrawSegments(dpy, d, ShadowGC, seg, i);
 	/* right */
-	for (i = 0; (i < line_width) && (i <= w / 2); i++) {
-		seg[i].x1 = x+w-i; seg[i].y1 = y+h-i-a;
-		seg[i].x2 = x+w-i; seg[i].y2 = y+i+1-a;
-	}
-	XDrawSegments(dpy, d, ShadowGC, seg, i);
-	/* draw top segments */
-	for (i = 0; (i < line_width) && (i <= h / 2); i++) {
-		seg[i].x1 = x+w-i-a; seg[i].y1 = y+i;
-		seg[i].x2 = x+i+1-a; seg[i].y2 = y+i;
+	i2 = i;
+	for (i = 0; (i < line_width) && (i <= w / 2); i++,i2++) {
+		seg[i2].x1 = x+w-i; seg[i2].y1 = y+h-i-a;
+		seg[i2].x2 = x+w-i; seg[i2].y2 = y+i+1-a;
 	}
-	XDrawSegments(dpy, d, ReliefGC, seg, i);
+	XDrawSegments(dpy, d, ShadowGC, seg, i2);
 
 	return;
 }

---

From: Dominik Vogt <[email-masked]>
Date: Wed, 24 Apr 2002 13:40:55 +0200

> within a week I propose we add it in to the repositary.

You are too cautious.  The patch is good and I'll apply it.
However, it does not help as much as you probably believe.  Since
there is no call to XFlush() between the several XDrawSegments
calls, all requests are queued on the client and sent some time
later, when the request buffer is flushed at some other place.
Therefore, there will be only one batch of communication between
the client and the X server, regardless of the number of calls to
XDrawSegments().  What you save is:  one half of the function
calls and a bit of bandwidth (four requests need more bytes to be
transmitted than two).

> >...

Bye

Dominik ^_^  ^_^

-- 
Dominik Vogt, email: [email-masked]
LifeBits Aktiengesellschaft, Albrechtstr. 9, D-72072 Tuebingen
fon: ++49 (0) 7071/7965-0, fax: ++49 (0) 7071/7965-20
--
Visit the official FVWM web page at <URL: http://www.fvwm.org/>.
To unsubscribe from the list, send "unsubscribe fvwm" in the body of a
message to [email-masked].
To report problems, send mail to [email-masked].