Slowdown when moving mouse cursor

For the Flash target and no other target, I notice that just moving the mouse around can slow down a game substantially for reasons that escape my grasp. The degradation is from 60 FPS down to 47-48, and I could even reproduce it on a completely blank pro…

  • Forums
  • »
  • Bugs
  • »
  • Slowdown when moving mouse cursor
Viewing 1 to 20 (23 Total)
Slowdown when moving mouse cursor

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

For the Flash target and no other target, I notice that just moving the mouse around can slow down a game substantially for reasons that escape my grasp. The degradation is from 60 FPS down to 47-48, and I could even reproduce it on a completely blank project with literally... nothing.

Other Observations
- Moving the cursor more violently worsens the slowdown
- Hiding the cursor has no effect. It's some underlying processing somewhere in the library, I reckon.

(I used's fermm's stats tool to visually see the FPS but also turned that off and eyeballed it and could easily see the choppiness)

For CPP or HTML5 targets, there is no such slowdown. Any ideas?

Tags:
Posted on June 01, 2012 at 3:04 AM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

By minimal, I literally mean this. You can grab fermm's stuff from here or ditch and test on your own.
http://www.haxenme.org/community/forums/general-discussion/i-want-t...

===

package;

import nme.Lib;
import nme.display.Sprite;
import nme.events.Event;
import nme.display.StageAlign;
import nme.display.StageScaleMode;

class Test extends Sprite
{
public function new()
{
super();
addEventListener(Event.ADDED_TO_STAGE, onAdded);
}

private function onAdded(event:Event):Void
{
init();
}

public function init()
{
Engine.stage = stage;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

var stats = new com.nmefermmmtools.debug.Stats();
stage.addChild(stats);
}

public static function main()
{
Lib.current.addChild(new Test());
}
}

I also did mouseEnabled/mouseChildren = false on this base test and that did nothing either.

Posted on June 01, 2012 at 3:19 AM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

Any insights on this? This is a showstopper for me.

Posted on June 04, 2012 at 4:22 AM

Philippe

Philippe
Total Posts: 262
Joined: September 08, 2011

Re: Slowdown when moving mouse cursor

That's an old Flash problem:
http://www.kirupa.com/forum/showthread.php?336138-Mouse-Movement-ca...

Posted on June 04, 2012 at 4:41 AM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

Thanks for the link, unfortunately, the only solution suggested that's relevant is mouseChildren / mouseEnabled = false, which I've already tried.

The other solutions don't apply (like the mouselistener), unless NME is doing something behind the scenes that I'm aware of. I'm playing directly out of the Flash player, so the other solution about transparent windows doesn't apply either.

Blitting solution sounds good, but it does not explain why I'm still seeing a slowdown in this blank project. Am I doing something wrong here?

---


package;

import nme.Lib;
import nme.display.Sprite;
import nme.events.Event;
import nme.display.StageAlign;
import nme.display.StageScaleMode;

class Test extends Sprite
{
public function new()
{
super();
addEventListener(Event.ADDED_TO_STAGE, onAdded);
}

private function onAdded(event:Event):Void
{
init();
}

public function init()
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

var stats = new com.nmefermmmtools.debug.Stats();
stage.addChild(stats);

mouseChildren = false;
mouseEnabled = false;

stage.mouseChildren = false;
}

public static function main()
{
Lib.current.addChild(new Test());
}
}

Posted on June 04, 2012 at 12:15 PM

singmajesty

singmajesty
Total Posts: 2192
Joined: August 25, 2011

Re: Slowdown when moving mouse cursor

How does this work for you?

import nme.display.FPS;
import nme.display.Sprite;

class Test extends Sprite {

public function new () {

super ();

addChild (new FPS ());

}

}


(You don't need a static main if you are using NME 3.3.2)

Posted on June 04, 2012 at 12:18 PM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

I'm still in 3.3.0 since I had some issues with the upgrade.

This still has the same issue though.


package;

import nme.Lib;
import nme.display.Sprite;
import nme.events.Event;
import nme.display.StageAlign;
import nme.display.StageScaleMode;

class Test extends Sprite
{
public static function main()
{
var fps = new com.nmefermmmtools.debug.Stats();
fps.mouseChildren = false; //with or without this, doesn't matter
Lib.current.addChild(fps);
}
}

Posted on June 04, 2012 at 12:25 PM

singmajesty

singmajesty
Total Posts: 2192
Joined: August 25, 2011

Re: Slowdown when moving mouse cursor

Okay, does this behave differently?

import nme.display.FPS;
import nme.display.Sprite;
import nme.Lib;

class Test extends Sprite {

public static function main () {

Lib.current.addChild (new FPS ());

}

}


...and are you sure it is a release build, and not debug?

There really is nothing special going on with an NME build for Flash, other than adding a preloader at the beginning.

Posted on June 04, 2012 at 12:27 PM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

Hmm, it's good now on that count. (I forgot all about the old FPS counter and equated it to the stats module!)

It's still slow on my engine, unfortunately - is it sufficient to walk through every node and set mouseChildren to false?

I guess it may be the same reason why using the stats module slows it down, perhaps.

Posted on June 04, 2012 at 12:39 PM

Philippe

Philippe
Total Posts: 262
Joined: September 08, 2011

Re: Slowdown when moving mouse cursor

You don't need to set mouseChildren on all child, just the container desired - and mouseEnabled on this container if needed.

NME doesn't do anything, it just maps all nme.* classes to Flash.

Do you have a "gamer" mouse with very high update rate?

Posted on June 04, 2012 at 1:48 PM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

I'll try again later today, but I did play around with setting the root container vs. everything.

I use a Logitech Anywhere Mouse MX - not gamer grade.

I'm not seeing slowdowns in any of the Flixel-based games I've outputted in the past and present, and trying to figure out what's different there.

Posted on June 04, 2012 at 1:55 PM

singmajesty

singmajesty
Total Posts: 2192
Joined: August 25, 2011

Re: Slowdown when moving mouse cursor

You'll get better performance if you poll the mouse position on Event.ENTER_FRAME rather than listening to MouseEvent.MOUSE_MOVE

...but I'm not sure if you're following the mouse position or not?

Posted on June 04, 2012 at 2:35 PM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

Nope, I'm not using the mouse move event - I'm polling on stage.mouseX/Y when I do it need it, and in the test game, I'm not even polling for mouse input at all.

Posted on June 04, 2012 at 3:54 PM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

It seems that this is a much more difficult problem to solve than originally anticipated.

- I fixed the slowdown caused by fermmm's Stats class. He was setting the htmltext for a TextField every update. I reduced it to once per second to match the update rate - issue solved.

- It appears that doing anything remotely CPU intensive like clearing a BitmapData sized to the game screen also causes problems. And this is a somewhat small screen we're talking about - 320x480.

Note that in neither of these cases does the framerate dip as long as I'm not moving the mouse around. It's the combination of the two that trips it off, and I already set mouseChildren and mouseEnabled to false on the root node.

Posted on June 05, 2012 at 12:54 AM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

Here's the double-kicker - this problem seems to be only for Macs. Inside a Windows VM no less, it has no issues at all with the framerate. :/

Posted on June 05, 2012 at 4:11 AM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

I finally pinned down the cause while doing some optimizations for mobile - though all the reasons above are true, I traced it back to an innocuous function that was polling on stage.mouseX and also doing some checks on a Sprite using its x/y/width/height.

What's really easy to forget is that each of those are function calls, and they could easily be doing other stuff behind the scenes. Whatever is going on in there on Flash or CPP, they were racking up an impressive load on the CPU and caching the values made the problem go away entirely.

But having to cache values - that takes away a lot from the convenience of the display list and makes me trust it less.

Posted on June 07, 2012 at 2:12 AM

Philippe

Philippe
Total Posts: 262
Joined: September 08, 2011

Re: Slowdown when moving mouse cursor

A display object's width isn't a trivial information, it often requires to do complex computations to measure children elements.

Posted on June 07, 2012 at 4:16 AM

Jon

Jon
Total Posts: 279
Joined: March 08, 2012

Re: Slowdown when moving mouse cursor

Can the same be said for setting the x/y position? I've found another piece of code that's bottlenecking and traced it down to something like

this.x += x;
this.y += y;

This causes a Flash game to plummet by 10 FPS. I noticed this early on when I was doing a simple 4-way keyboard tech demo and only re-realized it now.

Posted on June 07, 2012 at 12:04 PM

Philippe

Philippe
Total Posts: 262
Joined: September 08, 2011

Re: Slowdown when moving mouse cursor

Sometimes even reading .x has a little cost yes.
Basically everything that involves the display list means a communication between VM proxies and the native runtime.

Posted on June 07, 2012 at 12:28 PM

singmajesty

singmajesty
Total Posts: 2192
Joined: August 25, 2011

Re: Slowdown when moving mouse cursor

Do you experience performance hits like this if you use a native C++ desktop target or Neko desktop target rather than Flash Player?

Posted on June 07, 2012 at 12:40 PM
« Previous12Next »