[android-developers] Re: Game Stuttering

2010-06-23 Thread Zsolt Vasvari
Really?  The compiler is not smarting to turn the first into the
second?

On Jun 23, 5:48 am, Dan Sherman d...@nerd.com wrote:
 As far as I'm aware (someone correct me if I'm wrong), primitive types have
 no effect on garbage collection, especially local variables.

 A great example is:
 ListItem items;
 for (Item i : items) {
     // do something

 }

 When running will cause garbage collection, as each time that loop is
 called, it allocates an IteratorItem.  However the following would not.

 for (int i = 0; i  items.size(); i++) {
     Item it = items.get(i);



 }
 On Tue, Jun 22, 2010 at 5:31 PM, Neilz neilhorn...@gmail.com wrote:
  To discuss this point further...

  Does using Java primitive types still count in this scenario? Is it
  fine to create, for example, a number of int or boolean variables,
  within the game processing loop, or should these be created as static
  variables upon the class creation?

  To demonstrate, is:

  static int myVal;
  run(){
     myVal = x * y * z;
  }

  ...better than:

  run(){
     int myVal = x * y * z;
  }

  Thanks.

  On Jun 18, 8:37 pm, Dan Sherman d...@nerd.com wrote:
   Avoid allocations.

   Allocations = garbage collection.

  --
  You received this message because you are subscribed to the Google
  Groups Android Developers group.
  To post to this group, send email to android-developers@googlegroups.com
  To unsubscribe from this group, send email to
  android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubs­cr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en- Hide quoted text -

 - Show quoted text -

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Game Stuttering

2010-06-22 Thread Neilz
To discuss this point further...

Does using Java primitive types still count in this scenario? Is it
fine to create, for example, a number of int or boolean variables,
within the game processing loop, or should these be created as static
variables upon the class creation?

To demonstrate, is:

static int myVal;
run(){
myVal = x * y * z;
}

...better than:

run(){
int myVal = x * y * z;
}


Thanks.

On Jun 18, 8:37 pm, Dan Sherman d...@nerd.com wrote:
 Avoid allocations.

 Allocations = garbage collection.



-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Game Stuttering

2010-06-22 Thread Dan Sherman
As far as I'm aware (someone correct me if I'm wrong), primitive types have
no effect on garbage collection, especially local variables.

A great example is:
ListItem items;
for (Item i : items) {
// do something
}

When running will cause garbage collection, as each time that loop is
called, it allocates an IteratorItem.  However the following would not.

for (int i = 0; i  items.size(); i++) {
Item it = items.get(i);
}

On Tue, Jun 22, 2010 at 5:31 PM, Neilz neilhorn...@gmail.com wrote:

 To discuss this point further...

 Does using Java primitive types still count in this scenario? Is it
 fine to create, for example, a number of int or boolean variables,
 within the game processing loop, or should these be created as static
 variables upon the class creation?

 To demonstrate, is:

 static int myVal;
 run(){
myVal = x * y * z;
 }

 ...better than:

 run(){
int myVal = x * y * z;
 }


 Thanks.

 On Jun 18, 8:37 pm, Dan Sherman d...@nerd.com wrote:
  Avoid allocations.
 
  Allocations = garbage collection.
 
 

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Game Stuttering

2010-06-22 Thread Peter Eastman
I've also seen this sort of stuttering, which in my case is clearly
related to gc, since a message appears in the log saying that a gc was
just done whenever it happens.  I've used DDMS to identify where
garbage is being produced, and have completely eliminated all
allocations in my own code.  By I'm still seeing allocations in code
internal to Dalvik itself, and I haven't found any way to get rid of
them.

Peter

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Game Stuttering

2010-06-22 Thread Miguel Morales
Well, on a regular phone there will be a number of applications and
services running.
Even things like receiving an email or sms or other random events will
cause a GC at least once every 4 minutes.
I don't think there's a way to circumvent this without getting rid of
the allocations that happen in these programs.

I've heard that the newer 2.0 versions have improved garbage
collection hogging the cpu dramatically.  However I haven't done any
tests yet.

Do the GC runs happen in the emulator, or only on the phone?


On Tue, Jun 22, 2010 at 3:22 PM, Peter Eastman peter.east...@gmail.com wrote:
 I've also seen this sort of stuttering, which in my case is clearly
 related to gc, since a message appears in the log saying that a gc was
 just done whenever it happens.  I've used DDMS to identify where
 garbage is being produced, and have completely eliminated all
 allocations in my own code.  By I'm still seeing allocations in code
 internal to Dalvik itself, and I haven't found any way to get rid of
 them.

 Peter

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en



-- 
http://diastrofunk.com, http://developingthedream.blogspot.com/,
http://www.youtube.com/user/revoltingx, ~Isaiah 55:8-9

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Game Stuttering

2010-06-22 Thread Neilz
Yes, I think that's what's happening here too.

I used DDMS, and while I'm not 100% sure I'm reading it right, it
would appear that the allocations that are taking place are related to
Dalvik, and totally unrelated to my own code.

On Jun 22, 11:22 pm, Peter Eastman peter.east...@gmail.com wrote:
 I've also seen this sort of stuttering, which in my case is clearly
 related to gc, since a message appears in the log saying that a gc was
 just done whenever it happens.  I've used DDMS to identify where
 garbage is being produced, and have completely eliminated all
 allocations in my own code.  By I'm still seeing allocations in code
 internal to Dalvik itself, and I haven't found any way to get rid of
 them.

 Peter

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Game Stuttering

2010-06-22 Thread Miguel Morales
Well I wouldn't say that it's Dalvik itself, but rather the internal
java code for google apps like the sms messaging app, and the gmail
app, or any other service that runs in the phone.
I don't think that a ~200ms lag every 4 minutes is that bad, but I
guess it would depend on your type of game.
I'd recommend running your app in the emulator, I don't get any GC
runs when it's idle.  At least from the bit of testing that I did.
I know you won't be able to play your game in the emulator, but you
can at least verify no GC runs happen in your code.

However, I guess if you make enough noise, someone might try to fix this.
If anyone has a fix for this I'd be interested to hear it as well.

On Tue, Jun 22, 2010 at 3:37 PM, Neilz neilhorn...@gmail.com wrote:
 Yes, I think that's what's happening here too.

 I used DDMS, and while I'm not 100% sure I'm reading it right, it
 would appear that the allocations that are taking place are related to
 Dalvik, and totally unrelated to my own code.

 On Jun 22, 11:22 pm, Peter Eastman peter.east...@gmail.com wrote:
 I've also seen this sort of stuttering, which in my case is clearly
 related to gc, since a message appears in the log saying that a gc was
 just done whenever it happens.  I've used DDMS to identify where
 garbage is being produced, and have completely eliminated all
 allocations in my own code.  By I'm still seeing allocations in code
 internal to Dalvik itself, and I haven't found any way to get rid of
 them.

 Peter

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en



-- 
http://diastrofunk.com, http://developingthedream.blogspot.com/,
http://www.youtube.com/user/revoltingx, ~Isaiah 55:8-9

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Game Stuttering

2010-06-18 Thread lishali
I'm developing some games too, but when I want to find some articles
about the code optimisation, I find nothing.
I'm very interesting about how you can make your games has no GC when
it's running.
Thank you very much!

On Jun 15, 5:28 pm, Neilz neilhorn...@gmail.com wrote:
 Hi Charlie.

 Funny, I have exactly the same issue as you. I'm developing a game,
 where the sprite rendering is based loosely upon the google example
 SpriteMethodTest (using 2D Canvas drawing). I've gone through the code
 with a fine tooth comb, and applied all the tips for game
 optimisation, used DDMS, used the apd tracking tool, and still there
 are occasional stutters.

 Like you, I get no GC during the game. Also, I've tested on two
 devices (Hero 1.5 and Nexus 2.1) and it's the same.

 The game is looking playable, but it could be improved.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Game Stuttering

2010-06-18 Thread Dan Sherman
Avoid allocations.

Allocations = garbage collection.

On Tue, Jun 15, 2010 at 5:43 AM, lishali lishali12...@gmail.com wrote:

 I'm developing some games too, but when I want to find some articles
 about the code optimisation, I find nothing.
 I'm very interesting about how you can make your games has no GC when
 it's running.
 Thank you very much!

 On Jun 15, 5:28 pm, Neilz neilhorn...@gmail.com wrote:
  Hi Charlie.
 
  Funny, I have exactly the same issue as you. I'm developing a game,
  where the sprite rendering is based loosely upon the google example
  SpriteMethodTest (using 2D Canvas drawing). I've gone through the code
  with a fine tooth comb, and applied all the tips for game
  optimisation, used DDMS, used the apd tracking tool, and still there
  are occasional stutters.
 
  Like you, I get no GC during the game. Also, I've tested on two
  devices (Hero 1.5 and Nexus 2.1) and it's the same.
 
  The game is looking playable, but it could be improved.

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

[android-developers] Re: Game Stuttering

2010-06-15 Thread Nightwolf
Try to measure time needed to render each frame.
May be something's wrong with your game logic. For ex. thread
calculating new ingame positions is called too often and takes
precedence over rendering thread.

On Jun 14, 8:14 pm, czimm...@exit4gaming.com
czimm...@exit4gaming.com wrote:
 I have an issue with the OpenGL game I am developing that I am getting
 significant stuttering.  I have put in a lot of debug code to try to
 see if it is something I am doing, but I haven't had any success at
 narrowing down what is going on.  Stutters are between 80 msec and
 sometimes annoyingly as high as 200+ msec on my Droid.

 When the game is running, I don't think I am creating any garbage, but
 when I am initializing a level, I am definitely creating some
 garbage.  Just before starting the level, I give a hint to collect the
 garbage.  This got rid of a lot of my problems, but there is still
 stuttering going on.

 I put in some code to instrument the amount of time that I spend in
 various parts of my main rendering loop.  The stutters seem to happen
 randomly, each time in a different piece of code, so I am attributing
 them to something outside of my main loop code.  I also am NOT seeing
 the GC running when these stutter happen on the catlog.

 Is this services running while my game is running?  Is there a way to
 prevent this or at least mitigate the damage?

 I notice that sometimes the backlight on the menu keys (back/home/
 search etc.) is going on and off in sync to some of these stutters.
 Why is this happening?  I have orientation changes turned off and I
 don't think I understand what is going on with this backlight or why
 this would be related to the stutters.

 I have bumped my game up to MAX_PRIORITY and it seemed to help some,
 but did not get rid of this issue entirely.

 Can anyone help here or offer any suggestions on what could
 potentially be going wrong or with suggestions on how to debug this
 problem?

 Thanks,
 Charlie

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Game Stuttering

2010-06-15 Thread Neilz
Hi Charlie.

Funny, I have exactly the same issue as you. I'm developing a game,
where the sprite rendering is based loosely upon the google example
SpriteMethodTest (using 2D Canvas drawing). I've gone through the code
with a fine tooth comb, and applied all the tips for game
optimisation, used DDMS, used the apd tracking tool, and still there
are occasional stutters.

Like you, I get no GC during the game. Also, I've tested on two
devices (Hero 1.5 and Nexus 2.1) and it's the same.

The game is looking playable, but it could be improved.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Game Stuttering

2010-06-15 Thread czimm...@exit4gaming.com
Nellz,

Yes, this is really hard to figure out, which is why I am posting
here.  I am getting a consistent 40-50 FPS with my pretty complicated
3D app, but I get these wierd frames that take 100-200 msecs to run,
and it is unexplained for me.

NightWolf,

I have instrumented my code to try to see which methods are taking up
the time.  In fact, I have gone a lot finer than just seeing how long
a render takes.  I am timestamping and recording max deltas in several
spots in my movement code and I am timestamping and recording deltas
for the render code.

The delay appears randomly in all instrumented chunks of code, so it
doesn't seem specific to any code.  It seems like something else
other than my app.  Also, boosting my priority has helped but not
fixed the problem.  The fact that it helps also seems to point to
something else running.

When the glitch happens between when I have calculated the movement
and when I go to render the movement, then the game stutters.  When
the glitch happens between renders but not in between move and render,
then it is not so bad because the movement is accurately calculated
for the time that expired and the render happens soon afterwards.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Game Stuttering

2010-06-15 Thread Neilz
How do you boost the priority? That sounds like something I should try
out.

On Jun 15, 2:23 pm, czimm...@exit4gaming.com
czimm...@exit4gaming.com wrote:
 Nellz,

 Yes, this is really hard to figure out, which is why I am posting
 here.  I am getting a consistent 40-50 FPS with my pretty complicated
 3D app, but I get these wierd frames that take 100-200 msecs to run,
 and it is unexplained for me.

 NightWolf,

 I have instrumented my code to try to see which methods are taking up
 the time.  In fact, I have gone a lot finer than just seeing how long
 a render takes.  I am timestamping and recording max deltas in several
 spots in my movement code and I am timestamping and recording deltas
 for the render code.

 The delay appears randomly in all instrumented chunks of code, so it
 doesn't seem specific to any code.  It seems like something else
 other than my app.  Also, boosting my priority has helped but not
 fixed the problem.  The fact that it helps also seems to point to
 something else running.

 When the glitch happens between when I have calculated the movement
 and when I go to render the movement, then the game stutters.  When
 the glitch happens between renders but not in between move and render,
 then it is not so bad because the movement is accurately calculated
 for the time that expired and the render happens soon afterwards.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


[android-developers] Re: Game Stuttering

2010-06-15 Thread czimm...@exit4gaming.com
Thread myThread = Thread.currentThread();
myThread.setPriority(Thread.MAX_PRIORITY);

http://developer.android.com/reference/java/lang/Thread.html

On Jun 15, 9:28 am, Neilz neilhorn...@gmail.com wrote:
 How do you boost the priority? That sounds like something I should try
 out.

 On Jun 15, 2:23 pm, czimm...@exit4gaming.com



 czimm...@exit4gaming.com wrote:
  Nellz,

  Yes, this is really hard to figure out, which is why I am posting
  here.  I am getting a consistent 40-50 FPS with my pretty complicated
  3D app, but I get these wierd frames that take 100-200 msecs to run,
  and it is unexplained for me.

  NightWolf,

  I have instrumented my code to try to see which methods are taking up
  the time.  In fact, I have gone a lot finer than just seeing how long
  a render takes.  I am timestamping and recording max deltas in several
  spots in my movement code and I am timestamping and recording deltas
  for the render code.

  The delay appears randomly in all instrumented chunks of code, so it
  doesn't seem specific to any code.  It seems like something else
  other than my app.  Also, boosting my priority has helped but not
  fixed the problem.  The fact that it helps also seems to point to
  something else running.

  When the glitch happens between when I have calculated the movement
  and when I go to render the movement, then the game stutters.  When
  the glitch happens between renders but not in between move and render,
  then it is not so bad because the movement is accurately calculated
  for the time that expired and the render happens soon afterwards.

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Game Stuttering

2010-06-15 Thread Leigh McRae
There are issues with the system responding to touch events.  Search 
this group for more details.  The short of it is to use Thread.yield() 
in the onTouch.


Could the slow down be due to overdraw with stuff like particles?  So 
far on the Milestone the only 3d performance problem I have seen is 
fillrate/overdraw.


I wrote a very simple profiler that I can use to find roughly which 
areas are running slow.  I would invest time in doing this.  Even though 
this profiler is intrusive it still shows the areas.  Don't over 
engineer it.  A simple static list of profile points is all you need.  
Store stuff like number calls, total time, highest time etc. Spit out 
the profile once every couple of seconds.  BTW this is where a 
preprocessor can help buy conditionally compiling profiling out.


Make sure you're rendering is on it's own thread as it will block.

Add support to track the number of triangles rendered and spit it out 
once every 5 secs.


Make a toggle to shut off rendering and see what the framerate does so 
you can be sure it's not in the game sim.  Even better add support to 
toggle various systems off.



Leigh

On 6/15/2010 9:23 AM, czimm...@exit4gaming.com wrote:

Nellz,

Yes, this is really hard to figure out, which is why I am posting
here.  I am getting a consistent 40-50 FPS with my pretty complicated
3D app, but I get these wierd frames that take 100-200 msecs to run,
and it is unexplained for me.

NightWolf,

I have instrumented my code to try to see which methods are taking up
the time.  In fact, I have gone a lot finer than just seeing how long
a render takes.  I am timestamping and recording max deltas in several
spots in my movement code and I am timestamping and recording deltas
for the render code.

The delay appears randomly in all instrumented chunks of code, so it
doesn't seem specific to any code.  It seems like something else
other than my app.  Also, boosting my priority has helped but not
fixed the problem.  The fact that it helps also seems to point to
something else running.

When the glitch happens between when I have calculated the movement
and when I go to render the movement, then the game stutters.  When
the glitch happens between renders but not in between move and render,
then it is not so bad because the movement is accurately calculated
for the time that expired and the render happens soon afterwards.

   


--
Leigh McRae
www.lonedwarfgames.com

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en