Moving the mouse slows things down!

How strange.

So there I was cunningly testing the Steam build of Revenge of the Titans when I noticed the game lagging periodically - down to 50fps for a second and then back up to a rock steady 60fps. This is odd, I thought. Maybe it’s because the Steam build uses JRE6 server VM. Nope, does the same with the client VM. Maybe it’s because I’m not using the G1 GC (using -Xincgc instead). Nope, -verbose:gc shows I’m not collecting any garbage when the pauses happen.

So I stuck at it for half an hour, playing the game, and then I just let it run on a large empty survival map for a while with a few turrets, and didn’t touch anything. And there were no odd slowdowns as I watched. But as soon as I starting shoving the mouse around, scrolling and such with it - there’s the slowdown again. Whaa? My scrolling routines must be doing something wrong… so I checked using the keys to scroll (WASD or cursor keys if you didn’t know). And… no slowdown. Oh. So it’s not the scrolling. Must be some bit of mouseover code that’s slow then. So I put the mouse pointer in the middle of the action and scrolled around using the keys again making the mouse go over all sorts of different objects bringing up effects and so on … nope. No slowdown. I wiggle the mouse. Game slows down.

WTF!

And it happens in JDK7 - barely. But why do we think this is happening at all, eh?

This is JDK6 32-bit, on a Vista64 system with a quad core i7 running at 2.6Ghz and some graphics card that’s so fast it’s already calculated the recipe for rice pudding.

I am perplexed! Anybody else notice this behaviour? Is it JInput? Java? LWJGL?

Cas :slight_smile:

What happens to your CPU usage when moving the mouse over the desktop? (no applications running).

Keep in mind that the mouse-thread (in the OS) is running at the highest possible thread priority (critical / realtime). Maybe the interrupts are ‘interrupting’ your rendering thread at a very high interval, potentially worsened by a poorly written mouse driver.

just a random check, are you grabbing the mouse with LWJGL? do the pauses happen when LWJGL doesn’t grab the mouse?

Well, try it for yourself with a framerate graph and take a look.
Er.
Well, that’s a bit fiddly as you’ll have to download the .tar.gz linux version and then stuff 32-bit LWJGL dlls in there and twiddle the revenge.sh file to run.

But anyway: it’s not the mouse interrupts slowing things down, because they’re slowing things down from 60 to 50fps - massive. And my computer is nowhere near using all its CPU (not even 100% of one of its many cores) or GPU. And of course this only seems to occur in JDK6, not really noticable much in JDK7.

And here’s the next strange thing. It’s not doing it today :S

Cas :slight_smile:

fwiw, lwjgl is getting mouse move events and doing stuff with it. So try and disable those parts at least.
Consider checking with a profiler where the time is spend.