From: Ethan A M. <merritt@u.washington.edu> - 2004-05-09 23:44:51
|
On Sunday 09 May 2004 01:27 pm, Hans-Bernhard Broeker wrote: > On Fri, 7 May 2004, Daniel J Sebald wrote: >> gnuplot> load 'animate.dem' >> But if I hit return once again in the middle of the demo it >> will slow down its redraw rate significantly. > > I think that's the same old X11 multiple-stream handling problem again. Sort of. I added a time delay deliberately to handle a different problem, but this is an example of where it imposes a penalty. Let me explain what is going on, and you all can speak up as to how you want it handled. The issue is this. 1) When a plot (or replot) is started, the x11 driver sends a query to the X-server asking it some basic information like how big is the window and what size is the font being used. This allows much better plot layout. Because of this the x11 layout is much nicer in version 4, and the information is needed to support enhanced text mode for x11. 2) X11_waitforinput() now waits for the X-server to reply. 3) If terminal input comes in while it is waiting, X11_waitforinput() wakes up, notices that it isn't ready to handle new terminal input yet, and then loops back to the loop to wait again for the X-server to reply. 4) Problem #1 is that we don't want to read the terminal input at this point because that would cause characters to be lost. That's what it used to do, and there were lots of complaints. 5) Problem #2 is that once there is terminal input pending, the select() call returns immediately every time through the loop, so we sit there burning CPU cycles like mad until the X-server finally responds. There were complaints about this also. 6) So as a compromise, I put in a 1 second time delay before going back to the top of the loop and the select() call. Digression: I also added a maximum number of times through the loop, so that if the X-server never responds (should only happen in the case of a serious error, perhaps DISPLAY set to an incorrect value) there is still a maximum time elapsed before gnuplot returns to accepting terminal input. Even more recently I figured out how to allow ctrl-C to interrupt in the case of a jammed X-server, so this maximum loop count is no longer strictly necessary but it doesn't by itself hurt anything. 7) In the case of a real X-11 error, like a bad network connection, the 1 second delay is a small price to pay for handling a bad connection without locking up the CPU. In the case of a loop, however, even with a fully responsive X-server the unexpected terminal input causes a 1 second delay every time through the loop. I agree this is bad. Possible fixes: Make the time delay much smaller. On platforms with usleep() it could be some number of microseconds rather than a full second. As I recall, I originally I had usleep(100) but I switched to sleep(1) when I realized that not all platforms provide usleep(). Don't send the font+window size query if mousing is disabled. Then in the case of an animation loop you could just disable the mouse before entering the loop, and re-enable it afterwards if needed. I don't like this because if your original plot has mousing disabled, you will never get the info about window or font size. OTOH perhaps replot could handle this differently than plot (I'd have to look to see whether X11_waitforinput() can tell the difference). This would actually speed up the animation loop, since even if the X-server is responding normally the query/response cycle is kind of slow compared to everything else. Introduce a new command to toggle the query/response feedback. The internal mechanism is already in place, because some time back I added this as a command line option 'gnuplot -nofeedback' in order to allow people with problems to turn it off altogether. I don't like this because it's a command that would be specific to X11, and would just clutter up the command set. I tentatively propose to modify the time delay to be #ifdef HAVE_USLEEP usleep(100); #else sleep(1); #endif I am open to feedback about whether 'unset mouse' should disable the size+font query altogether in the case of a replot, or the question of having an explicit command to disable it. Ethan -- Ethan A Merritt Department of Biochemistry & Biomolecular Structure Center University of Washington, Seattle |