Stutter after upgrading to v43

Monkey Targets Forums/Android/Stutter after upgrading to v43

devolonter(Posted 2011) [#1]
That's strange. After upgrading to v43 my port Impact ( https://github.com/devolonter/Impact/tree/unstable ) for Android begin to "stutter" on my Desire Z (Android 2.2). If you have an opportunity please, compare two versions 1.06 and 1.10a of section https://github.com/devolonter/Impact/downloads


anawiki(Posted 2011) [#2]
I noticed the same for my game. It might have something to do with HICOLOR_TEXTURES=true (means using 32 bit textures), but I'm still testing it.

I am so disappointed with Android devices. Last Friday I checked my game on 4th gen iPod and it worked almost 60 FPS, while Samsung Galaxy Tab p1010 (7") barely gets to 40FPS.


devolonter(Posted 2011) [#3]
@anawiki I've tried to set HICOLOR_TEXTURES = false, but this has not led to any changes on my device :(


anawiki(Posted 2011) [#4]
on mine too... which makes me very disappointed


therevills(Posted 2011) [#5]
Just tested Impact on my LG Optimus One P500, I would say that the 1.10a runs better than the 1.06. And I saw a stutter on the 1.06...


anawiki(Posted 2011) [#6]
don't see a big difference in performance for both versions on galaxy tab. maybe if you had FPS counter displayed would be easier to compare.


anawiki(Posted 2011) [#7]
Not sure about your but I just installed 2 versions of my game on galaxy tab - one compiled in v42b and one in v43.

v42b - 32-34 FPS
v43 - 16-18 FPS

What happened? Is that just the fact of using VBO?


arcsrc(Posted 2011) [#8]
I didn't do any FPS comparison but the first thing i noticed after compiling my game on v43 was the stuttering. I tested on a Galaxy S.


therevills(Posted 2011) [#9]
How does Replica Island work for your devices?

http://code.google.com/p/replicaisland/

Replica Island uses VBOs when it can...


dave.h(Posted 2011) [#10]
plays perfect on my experia x10


devolonter(Posted 2011) [#11]
I spent the whole day testing v43, but unfortunately it did not come to any conclusions. The only thing that I've noticed in v43: my device is noticeably get hot (really a lot), FPS can jump from 20 to a comfortable 55-58 at the same time it's hard to find some kind of dependence ... Perhaps the problem is in high loading CPU?

@Anawiki I built an application with FPS. On the game screen, I got the following results: v42b - 56-58FPS, v43 - 25-30FPS (sometimes grows to 50). I upload the update to my server - http://devolonter.ru/impact_fps.zip Just wanted to know if I could somehow test your game?

@Therevills Replica Island works fine on my device


AdamRedwoods(Posted 2011) [#12]
@devolonter: No stuttering on Galaxy Tab.

Note to FPS on different devices:
Phones and smaller screens have less pixels to update, so you will get better frame rates.

Here's a site that explains it on iPad:
http://www.fabiensanglard.net/fillrate_issues/


AdamRedwoods(Posted 2011) [#13]
The other note about stuttering is be careful how much Object creation/destroying you do, as the garbage collection may slow things down.
Try using a pre-allocated pool of objects.

http://fanitis.com/2011/02/09/android-game-performance-garbage-collection/

Or Not:
http://stackoverflow.com/questions/4900014/is-it-impossible-to-make-an-android-game-stutter-free-i-am-going-crazy-here


My last thought is that PHONES will be looking for signals, calls, messages, etc, in the background. This will cause stuttering. Maybe this is why the Galaxy Tab Wifi does not stutter.


therevills(Posted 2011) [#14]
@devolonter - just downloaded the fps versions.

           | v42b  |  v43
-----------+-------+------
Titlescreen| 24-27 | 46-50
Gamescreen | 55-59 | 23-30


At least the titlescreen runs alot better in v43... :/


anawiki(Posted 2011) [#15]
Garbage collection is not an issue in my game. Remember, that's the same code, just compiled in two Monkey versions: v42b and v43. When I watch DDMS it shows that GC doesn't kick in more often than once per 2 seconds. There are of course parts in my game where GC kicks in a lot and I don;t get many FPS, but for game screen I had ~36 FPS and now I don't.

I am compiling in release mode.


jowli(Posted 2011) [#16]
I've lost at least 20 FPS as well, which including the FPS lost in previous monkey updates means I am down to my last 5 FPS!
It feels like we are missing something here, seems as though most of us are not getting the expected performance boost.

It would be good to know more about how we should be using the HICOLOR_TEXTURES flag.

The other odd thing I noticed is that when compiling in eclipse, I get 5 warnings complaining about 'Dead code'. Every one of these relates to a line of code containing the MonkeyData.HICOLOR_TEXTURES flag. e.g.

if( MonkeyData.HICOLOR_TEXTURES && hasAlpha ){
...


devolonter(Posted 2011) [#17]
@therevills It's not so bad:) In most of the tests, I found out 15-20% FPS gain in comparison with the version v42b. So I think V43 is nevertheless faster, it is necessary to understand why it doesn't work in real games.

As for the stuttering. I have carried out a small test (with a minimum number of objects) which excludes at least some loss of FPS, and have found out that stuttering remain even in this case. Thus, they occur at regular intervals, that suggests about a problem with FPS stabilization. I do not know what mechanism of stabilization is used in mojo, and it seems, it does not work very well for Android, also the same situation was noticed in XNA target, but there it is less expressed.

Here is a source code of the test. This is a slightly modified code from this post - http://www.monkeycoder.co.nz/Community/post.php?topic=869&post=7366 :




jowli(Posted 2011) [#18]
Ignore what I said about the 'Dead code', I realised what it is; HICOLOR_TEXTURES is static, so branches of the code will never get called depending on it value.


AdamRedwoods(Posted 2011) [#19]
devolonter test
v42b
(with the rocket in bananas folder, and 461x516 png arbitrary galaxy):

10 objects---
I get 37 - 42 fps on the Galaxy Tab Wifi. Almost no stuttering.

80 objects---
22 - 28 fps Galaxy Tab wifi, small amounts of stuttering.


devolonter(Posted 2011) [#20]
@AdamRedwoods thanks for testing. It seems all devices behave absolutely differently (


therevills(Posted 2011) [#21]
@devolonter - just looking thru your Impact code and I do notice that you are not using any sort of delta timing for movement:

asteroid.monkey:
Method OnUpdate:Void()
	frame += ANIM_SPEED
	If (frame >= FRAMES) Then frame -= FRAMES
	x += dx
	y += dy
	If (x < -32 Or x > Application.WIDTH + 32 Or y > Application.HEIGHT + 32) Then Destroy()
End


If you add in delta timing it might help your stuttering.

Const FPS:Int = 60
' Used for delta timing movement
Global dt:DeltaTimer = New DeltaTimer(FPS)

Class MyGameApp Extends App
...
	Method OnUpdate:Int()
		dt.UpdateDelta()
...
End

' From James Boyd
Class DeltaTimer
	Field targetfps:Float = 60
	Field currentticks:Float
	Field lastticks:Float
	Field frametime:Float
	Field delta:Float
	
	Method New (fps:Float)
		targetfps = fps
		lastticks = Millisecs()
	End
	
	Method UpdateDelta:Void()
		currentticks = Millisecs()
		frametime = currentticks - lastticks
		delta = frametime / (1000.0 / targetfps)
		lastticks = currentticks
	End
End


And use it like this:

	x += dx * dt.delta
	y += dy * dt.delta



muddy_shoes(Posted 2011) [#22]
I suggest that you guys start timing the updates and render calls separately. The mojo update loop does not necessarily exhibit a smooth degradation in rendered frames when your game can't keep up with the requested update rate.


AdamRedwoods(Posted 2011) [#23]
I get a slight drop of 2-4 FPS after updating to v43 with the above demo.
Galaxy Tab wifi.
Sorry.


devolonter(Posted 2011) [#24]
@therevills thank you! I really missed it. I added delta timing locally, this made the movements more smooth, but unfortunately it did not save from the global stuttering :( At some instant time objects begin to move terribly slowly, and then abruptly quickly. It looks like an stuck record... In the near future I'll post a video, that shows it.


devolonter(Posted 2011) [#25]
These videos show stuttering, which I see after upgrade to v43. I do not see anything like this in v42b.
http://www.youtube.com/watch?v=fbWvfFO9AMw (from 00:47 second)
http://www.youtube.com/watch?v=CIChaSOY_S0

After two days of tests I did not come to any conclusions, and I'm upset ... While searching for a solution I looked through another open-source game engines for android. And stumbled upon andengine - http://www.andengine.org/. Author uploaded on Android.Market ( https://market.android.com/details?id=org.anddev.andengine.examples ) examples, so I had the opportunity to evaluate his work. None of the examples had such stuttering, all object's movements were very smooth. May be one should try to write the mojo alternative with the same interface and architecture based on this framework?


MonkeyPig(Posted 2011) [#26]
This may or may not help, but I had similar issues with stuttering on Android and figured it was garbage collection. I attached DDM and sure enough in the log I could see significant time being spent in GC every couple of seconds.

Using the Allocation Tracker in DDM I was able to see where in my code the offending allocations where and removed them until they were all gone (well almost all - I know of a couple that need a little more work to remove).

There are still many allocations happening as part of the Android system - but none that directly relate to my sloppy Monkey(ing) around.

Things to be aware of - Strings create allocations. I reworked my HUD to rework stuff like lives:String = m_NumLives. DrawText(lives). The java string builder was creating allocations as a result of this simple Monkey code.

Avoid using For Eachin because the iterator creates a temp allocation.

Multiply that by the framerate you're running at and the every couple of seconds the garbage collector cleans up. Slowly.

NOTE: I'm no android expert - so I may be wrong on this. This was just what I could measure and appear to remedy with the changes I outline above.


AdamRedwoods(Posted 2011) [#27]
Sorry for the messy code, but I wonder if converting to an array instead of a sprite list will remove the stuttering. Seemed to do ok for me.




devolonter(Posted 2011) [#28]
@AdamRedwoods In my opinion objects move more smoothly

Today I've experimented directly with mojo code for Android target. I've tried to change the update logic and application rendering based on existing open source frameworks.

It has gave the results in tests too. I've got smoother objects movement and the problem of sharp loss FPS has gone, but in the game everything hasn't improved considerably, though nevertheless some there was some improvement.

Unfortunately, I cannot describe all changes that I've made in a mojo code, because there are a lot of them and I can not upload code in open access since it still contains a lot of an original mojo code and I think Mark will disapprove of it. But I can send my mojo.android.java version on email to everyone (please write on mail, not to clutter up theme, in a letter indicate your nickname on the site). I'm curious to know your results. Maybe this will help to solve the problem.

I have written a small test: http://devolonter.ru/MonkeyRenderTest.zip All test run in release mode. V43 X - Monkey v43 with my mojo version.

Solid
         +--------+--------+--------+
 Objects |  V42b  |  V43   |  V43 X |
+--------+--------+--------+--------+
| 10     |   58   |   58   |   58   |
+--------+--------+--------+--------+
| 50     |   58   |   58   |   58   |
+--------+--------+--------+--------+
| 100    |   49   |   58   |   58   |
+--------+--------+--------+--------+
| 150    |   37   |   58   |   58   |
+--------+--------+--------+--------+
| 200    |   29   |  27-30 |   58   |
+--------+--------+--------+--------+
| 250    |   24   |  25-27 |   58   |
+--------+--------+--------+--------+
| 300    |   21   |  25-26 |  57-58 |
+--------+--------+--------+--------+

Alpha
         +--------+--------+--------+
 Objects |  V42b  |  V43   |  V43 X |
+--------+--------+--------+--------+
| 10     |   58   |   58   |   58   |
+--------+--------+--------+--------+
| 50     |   58   |   58   |   58   |
+--------+--------+--------+--------+
| 100    |   49   |   58   |   58   |
+--------+--------+--------+--------+
| 150    |   37   |   58   |   58   |
+--------+--------+--------+--------+
| 200    |   30   |  30-31 |   58   |
+--------+--------+--------+--------+
| 250    |   25   |  28-30 |   58   |
+--------+--------+--------+--------+
| 300    |   21   |  26-29 |  57-58 |
+--------+--------+--------+--------+

Animated
         +--------+--------+--------+
 Objects |  V42b  |  V43   |  V43 X |
+--------+--------+--------+--------+
| 10     |   58   |   58   |   58   |
+--------+--------+--------+--------+
| 50     |   58   |   58   |   58   |
+--------+--------+--------+--------+
| 100    |   48   |   58   |   58   |
+--------+--------+--------+--------+
| 150    |   36   |   58   |   58   |
+--------+--------+--------+--------+
| 200    |  28-29 |  50-52 |   58   |
+--------+--------+--------+--------+
| 250    |  23-24 |  46-48 |   58   |
+--------+--------+--------+--------+
| 300    |  20-21 |  45-48 |  57-58 |
+--------+--------+--------+--------+

Colorize
         +--------+--------+--------+
 Objects |  V42b  |  V43   |  V43 X |
+--------+--------+--------+--------+
| 10     |   58   |   58   |   58   |
+--------+--------+--------+--------+
| 50     |   58   |   58   |   58   |
+--------+--------+--------+--------+
| 100    |   48   |   58   |   58   |
+--------+--------+--------+--------+
| 150    |   36   |   58   |   58   |
+--------+--------+--------+--------+
| 200    |  28-29 |  55-56 |  56-58 |
+--------+--------+--------+--------+
| 250    |  23-24 |  48-49 |  55-56 |
+--------+--------+--------+--------+
| 300    |  20-21 |  40-42 |  51-52 |
+--------+--------+--------+--------+



therevills(Posted 2011) [#29]
Wow some serious improvements there!

Can you describe your improvements and what open source framework did you base it on?


devolonter(Posted 2011) [#30]
Major changes: the main loop moved into thread, RenderMode changed to - RENDERMODE_CONTINUOUSLY. This often causes the renderer, but it's worth it. I also modified onTouch method (reduced use of reflection to a minimum), but it does not matter in this test. My version was based on andengine ( http://www.andengine.org/ )

About performance improvement... In some tests original v43 sharply reduced FPS and it's happened several times, so values in the table are much different, in fact I think the real improvement can be seen in the Animated and Colorize tables. What I say for sure - this is a very smooth motion for 58 FPS in my version, so at least this is an improvement :) But we need more tests. If you want I'll send you my version on email.


marksibly(Posted 2011) [#31]
Hi,

Looking good! Can you send me the code?


therevills(Posted 2011) [#32]
Mark sent me the file:

S = Solid
A = Alpha
An = Animated
C = Colorize

         +--------+--------+--------+--------+++--------+--------+--------+--------+++--------+--------+--------+--------++
 Objects |  V42bS |  V42bA |  V42bAn|  V42bC |||  V43S  |  V43A  |  V43 An|  V43 C |||  V43XS |  V43XA |  V43XAn|  V43XC ||
+--------+--------+--------+--------+--------+++--------+--------+--------+--------+++--------+--------+--------+--------++
| 10     |   59   |   59   |   59   |   59   |||   60   |   60   |   60   |   60   |||   59   |   60   |   60   |   58   ||
+--------+--------+--------+--------+--------+++--------+--------+--------+--------+++--------+--------+--------+--------++
| 50     |   36   |   36   |   35   |   35   |||   59   |   59   |   59   |   59   |||   59   |   59   |   59   |   59   ||
+--------+--------+--------+--------+--------+++--------+--------+--------+--------+++--------+--------+--------+--------++
| 100    |   22   |   22   |   22   |   21   |||   48   |   43   |   43   |   43   |||   44   |   44   |   44   |   44   ||
+--------+--------+--------+--------+--------+++--------+--------+--------+--------+++--------+--------+--------+--------++
| 150    |   15   |   15   |   15   |   15   |||   42   |   43   |   41   |   40   ||| 37-44  |  37-44 |   37   |   42   ||
+--------+--------+--------+--------+--------+++--------+--------+--------+--------+++--------+--------+--------+--------++
| 200    |   12   |  12    |   12   |   11   |||   29   |   30   |   29   |   29   |||   29   |  29    |   29   |   29   ||
+--------+--------+--------+--------+--------+++--------+--------+--------+--------+++--------+--------+--------+--------++
| 250    |   9    |  9     |   9    |   9    |||   27   |   27   |   27   |   27   |||   25   |  26    |   25   |   24   ||
+--------+--------+--------+--------+--------+++--------+--------+--------+--------+++--------+--------+--------+--------++
| 300    |   7    |  7     |   7    |   7    |||   23   |   23   |   23   |   22   |||   22   |  22    |   22   |   21   ||
+--------+--------+--------+--------+--------+++--------+--------+--------+--------+++--------+--------+--------+--------++


So the 43X is slightly worse on my phone with that RenderTest. Now testing Pirates...

Level 1, Hand 1 (30 cards on the game field):
    | FPS
----+---------
42b | 31-35
43  | 22-28
43X | 20-26



devolonter(Posted 2011) [#33]
@therevills Thanks for testing! It is a pity that the results were not as good as mine. I sent you a new version, it can change something...


therevills(Posted 2011) [#34]
No problem - Thanks for helping with this issue.

         +--------+--------+--------+--------+
 Objects |  V43X1S|  V43X1A| V43X1An|  V43X1C|
+--------+--------+--------+--------+--------+
| 10     |   59   |   59   |   59   |   59   |
+--------+--------+--------+--------+--------+
| 50     |   59   |   59   |   59   |   59   |
+--------+--------+--------+--------+--------+
| 100    |   44   |   44   |   44   |   44   |
+--------+--------+--------+--------+--------+
| 150    |   39   |   39   |   39   |   38   |
+--------+--------+--------+--------+--------+
| 200    |   31   |   31   |   30   |   30   |
+--------+--------+--------+--------+--------+
| 250    |   26   |   26   |   26   |   26   |
+--------+--------+--------+--------+--------+
| 300    |   22   |   22   |   22   |   22   |
+--------+--------+--------+--------+--------+


Pirates now get between 21-26FPS...


devolonter(Posted 2011) [#35]
@therevills Thank you! I continue to research andengine code, searching for solution of rendering performance. If there are some results I'll let you know