Display.update() frequently takes a long time

Started by avm1979, June 06, 2010, 23:14:06

Previous topic - Next topic

avm1979

I've noticed that calling Display.update() will take an unusually long time once or twice a second (~15-50ms, where the usual is 0-1ms.  This ends up causing a noticeable stutter in the application.

Tried various configurations (vsync/no vsync, calling Display.sync(60) vs using Thread.sleep, calling Display.update(false)), but nothing made much difference.

I'm running on windows XP with an NVIDIA GeForce 8800 GTS 512 video card.  Tried the app on a macbook and the problem does not show up!

Does anybody have any idea what might be causing this?  I'm about to tear my hair out  :)

Edit: I'm using LWJGL version 2.4.2

Edit #2: I've reduced the main loop to the following:

while (true) {
      Display.sync(60);
      long now = GLUtils.getTime();
      Display.update(true);
      long then = GLUtils.getTime();
      long delta = then - now;
      if (delta > 20) {
         System.out.println("Display.update() time:" + delta + "ms");
      }
   }


and it produces this output over the course of maybe 5 seconds:

Display.update() time:22ms
Display.update() time:27ms
Display.update() time:24ms
Display.update() time:30ms
Display.update() time:34ms
Display.update() time:35ms
Display.update() time:22ms
Display.update() time:34ms
Display.update() time:27ms

Elviz

Do you have "Threaded optimization" set to Auto (or On) in the NVIDIA control panel? If so, try turning it off and then running your test again.

avm1979

Thanks for the suggestion!

Hm, weird - when I run the pared-down main loop from the above post, tweaking this setting didn't seem to do anything.  But, when I run the real main loop, Display.update() no longer takes up the time - the rendering code does.

But, and this is where it gets weird - as I pare down the main loop and remove rendering bit by bit, eventually it switches over to where Display.update() once again takes the extra time.  So with threaded optimization turned off, it just seems like this extra time is spread around differently.

Edit: After updating to the latest drivers (197.45), the problem is about twice as bad (the delays are longer) and it appears to be everywhere (not just the app).  Other games, and I can even see it dragging a window around.  Argh!!!

Matthias

Do you have any glGet* calls in your code? This interacts with a threaded driver and causes synchronization. Also check with -verbose:gc if you have high GC activity.

Of course this won't help with your other apps (which I find strange).

Matzon

Quote from: avm1979 on June 07, 2010, 04:16:38Other games, and I can even see it dragging a window around.  Argh!!!
Dragging a window around is actually a problematic case itself for many apps. Basically, under windows, whenever you initiate a drag and until you release the drag, the event queue will go into a sub-queue that will not process paint events. You basically have to manually fire a timer to do the paint. I've tried to fix it in lwjgl but its always been very hackish - since we rely on the event thread making the paint calls (using another thread would cause issues with invalid contexts and what not.).

So, dont rely on updates while dragging windows.

avm1979

Quote
Do you have any glGet* calls in your code? This interacts with a threaded driver and causes synchronization. Also check with -verbose:gc if you have high GC activity.

Nope, no glGet type calls.  Tried verbose gc, it's not very frequent and I haven't seen it take more than 2-3ms.


Quote
So, dont rely on updates while dragging windows.

I meant dragging file explorer windows and the like, sorry that was ambiguous.  Good to know anyway.


I'm pretty sure now it's a driver/video card issue.  Updating to the latest beta drivers (257 dot something or other) made it worse still (the stutter would span several frames, leading to a slow-motion effect of sorts every second...), while going to 178.24 helped considerably, though didn't fix it altogether.

Well, on the bright side, I'm pretty sure it's not an LWJGL issue :)

sargon

I have this same issue, almost a year later.  I wonder if there was ever any solution...  I have a GeForce GTX 285.  No glGet calls, and I've verified with verbose GC that it's not the GC.  I tried "Threaded optimization" set to off and it made no difference.

avm1979

Take a look at this post.  That's what ended up finally fully resolving the issue for me.

sargon

Quote from: avm1979 on April 27, 2011, 16:16:46
Take a look at this post.  That's what ended up finally fully resolving the issue for me.

Hmm, that didn't help.  The problem is that Display.update() is taking a long time, not that sync() is uneven.  Even if I don't call sync at all, update still takes >30ms once or twice a second.

sargon

Ah, I updated my nvidia drivers to 270.61 and that solved the issue.