Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android rendering performance issue #15652

Closed
minggo opened this issue May 16, 2016 · 200 comments
Closed

Android rendering performance issue #15652

minggo opened this issue May 16, 2016 · 200 comments
Assignees
Milestone

Comments

@minggo
Copy link
Contributor

minggo commented May 16, 2016

Some developers report there is performance issue on Android, specially on Android 6.0 + QHD devices. There are also many tickets in forum reporting about it: http://discuss.cocos2d-x.org/t/cocos2d-x-and-poor-updates/29296.

@minggo
Copy link
Contributor Author

minggo commented May 17, 2016

Run cpp-tests on Xiaomi4 with Android 6.0.1, its resolution is 1920*1080. Its FPS is 59-60, not performance issue.

@PorkyPixels
Copy link

I have the performance issues on my game and it appears to be something to do with SimpleAudioEngine?

My game makes a sound every time you tap the screen. When tapping the screen on an Android 6 device, the game stutters quite badly. I found that disabling the sound effects (but leaving the background music playing) stops all stuttering and the game runs at a smooth 60fps.

Cocos2D-X 3.10
Android 6.0
Device: Elephone P9000

The game works fine on my Android 5.1 Amazon Fire tablet, which is a much lower spec device.

@minggo
Copy link
Contributor Author

minggo commented May 17, 2016

@PorkyPixels Thanks for your information. Why not use new Audio engine? It uses OpenSL and have good performance.

@larsven
Copy link

larsven commented May 17, 2016

@minggo one reason could be it is still "experimental"

@PorkyPixels
Copy link

@minggo I use SimpleAudioEngine as I'm familiar with it and never had a problem with it before. Thanks for the suggestion though, I will look into the the new audio engine and see if that resolves the issues on Android 6.

@minggo
Copy link
Contributor Author

minggo commented May 17, 2016

@larsven the only reason that it is named experimental is only because it is not implemented on all platforms. That's @ricardoquesada required.

@larsven
Copy link

larsven commented May 17, 2016

@minggo ok thanks for the info

@iPruch
Copy link

iPruch commented May 17, 2016

I started developing an infinite runner game last year, starting with Cocos2d-x 3.6 and I've been updating the cocos version up to 3.9 (and not further because I stopped developing the game for now, but I plan to work on finishing it soon). It has always performed great on iOS devices (even on an old iPhone 4), but Android has always been some steps behind. From my experience, Android devices can also reach 60 FPS but they generally are less constant, with some random lagging. And there's the audio problem (both with SimpleAudio and experimental, although experimental seems to perform better): Sometimes when I play a sound, there's a noticeable lag (FPS slightly drop for an instant).

Let's be more concrete: All the following tests were made with a build of my game with Cocos2d-x v3.9 (I didn't notice big differences in performance from 3.6, 3.7 or 3.8, so that's why I'm only sharing 3.9 results)

  • LG G3 (LG-D855) with Android 5.0: The game runs at 50-60 FPS. Playing sounds can cause small noticeable rendering lags. It's perfectly playable, but kind of surprising for such a powerful device to present those performance issues.
  • LG G3 (LG-D855) with Android 6.0: Since I finally updated my smartphone, the game's performance has worsen. When the game starts running it behaves similarly to when I had Android 5.0, but after some seconds (10-30 seconds of gameplay) the FPS starts fluctuating too much, like a sequence of 1 smooth (50-60 FPS) second of gameplay followed by 5 seconds of stuttering (10-30 FPS, fluctuating a lot), then again 1 second smooth, and so on.

Also, testing older and less capable Android devices I was surprised to discover that the game got very low FPS on some Samsung devices while it ran decently well on an older one. See:

  • Samsung Galaxy mini (S5570) with Android 2.3.6: 40-50 FPS. Incredibly good performance considering the little power of the device. Playing sounds has a greater impact on FPS (dropping to 15-20 FPS).
  • Samsung Galaxy Tab 3 (7.0) with Android 4 (don't remember the specific version): 15-20 FPS. Unbelievable considering that the Galaxy mini achieves 40-50 FPS. Playing sounds also make FPS to drop significantly.
  • Samsung Galaxy S III mini (I8200) with Android 4 (don't remember the specific version): Very similar to the Galaxy Tab 3's behavior.

http://www.gsmarena.com/compare.php3?idPhone1=3725&&idPhone2=6190&idPhone3=5422

Also tried on a Motorola Moto G (1) and it achieved 60 FPS with Android 4, same small FPS drops when playing sounds as the LG G3. Similar behavior with a Nexus 4 with Android 5.

I hope this helps! And if there's anything I can test with the devices I still own, just tell me (Samsung Galaxy mini, LG G3, iPhone 4, iPod Touch 6th gen, iPad mini) and I'll try if I can.

@minggo
Copy link
Contributor Author

minggo commented May 18, 2016

@iPruch thanks for the detail information. It seems it is Android OS version and Android device related. What i can find is that the audio engine will affect performance issue on all situations. I found Android provide high performance Audio, hope it is so high performanne as it says.

Edit: AudioEngine already uses OpenSL ES.

@minggo
Copy link
Contributor Author

minggo commented May 18, 2016

@iPruch could you please update Samsung Galaxy mini (S5570) to Android 6 to have a test too. I just want to make sure if Android 6 causes performance issue.

@iPruch
Copy link

iPruch commented May 18, 2016

@minggo I don't think that such an old device can officially update that far, and also I wanted to keep it with 2.3.6 to have an old Android device to test. Maybe an Android 6 ROM can be flashed, but I've never done that before and I don't know the process and risks. I'll take a look

@minggo
Copy link
Contributor Author

minggo commented May 18, 2016

@iPruch I found the specification of Samsung Galaxy mini (S5570) and Samsung Galaxy Tab 3 (7.0). It seems S5570 has more powerful of CPU and less powerful of GPU:

  • S5570
    • CPU: Quad-core 1.4 GHz Cortex-A7
    • GPU: Mali-400MP4: four cores
      (so called fragment processors) and a vertex processor
    • resolution: 720 x 1280 pixels (~326 ppi pixel density)
  • Samsung Galaxy Tab 3 (7.0)
    • CPU: Dual-core 1.2 GHz Cortex-A9
    • GPU: PowerVR SGX540: 4 pixel and 2 vertex shaders that are usually clocked at 200 MHz.
    • resolution: 600 x 1024 pixels (~170 ppi pixel density)

So may be the bottleneck is on CPU? Could you please use NDK profiler to have a try?

@iPruch
Copy link

iPruch commented May 18, 2016

@minggo No, that is not the Samsung Galaxy mini S5570. This is it: http://www.gsmarena.com/samsung_galaxy_mini_s5570-3725.php

Much older and powerless: Just 1 core @ 600 MHz and Adreno 200 GPU

@minggo
Copy link
Contributor Author

minggo commented May 18, 2016

Oh, its resolution is 240 x 320 pixels (~127 ppi pixel density), so it is GPU related.

@minggo
Copy link
Contributor Author

minggo commented May 18, 2016

Because cocos2d-x is a 2d game, almost all objects are drawn in the same layer(the z is 0), so the overlap issue is more serious because z-test has not effect.

@iPruch
Copy link

iPruch commented May 18, 2016

@minggo But what I was saying on my first and long post above is that the S5570 performance is good (around 45 FPS) considering the lack of power of the device, and other devices as the Tab 3 only achieve around 20 FPS being more powerful. I think sometime ago I saw a thread on the Cocos2d-x forum about the bad performance in some Samsung devices being fault of Samsung's custom implementations of some Android core parts. I'll post it here if I find the thread

@minggo
Copy link
Contributor Author

minggo commented May 18, 2016

Yep, because S5570's resolution is much lower than Galaxy Tab 3.

@iPruch
Copy link

iPruch commented May 18, 2016

@minggo Ok, I didn't understand you at first.

@iPruch
Copy link

iPruch commented May 18, 2016

Maybe the Samsung devices low FPS problem is due to the power saving mode? http://stackoverflow.com/a/17670350

It's a shame that I can't test it with those Tab 3 and S III mini because I don't have them anymore.

@niekvse
Copy link

niekvse commented May 23, 2016

I'm experiencing a similar issue (Cocos2d-x 3.10)

I'm showing a Scene, and tested on these two Android phones:

  • LG Nexus 5x (2015, Snapdragon 808, Android 6.0.1, resolution 1080 x 1920)
  • HTC One M7 (2013, Android 5.0.2, resolution 1080 x 1920)

On the Nexus 5x, I get an FPS of 11-13.
On the HTC (a much older, slower phone), I get an FPS of 60.

Same APK, same Scene, same resolution. The scene has about 165 sprites. No sound is used anywhere. No labels are used. I haven't activated any kind of power saving modes.

I'm using the following Node types:

Layer (as a base of the Scene)
Sprite (some using createWithSpriteFrameName)
DrawNode
Node

@minggo
Copy link
Contributor Author

minggo commented May 24, 2016

@niekvse Thanks. Could you share the codes? I can find Nexus 5 to test, but i don't have Nexus 5x.

@niekvse
Copy link

niekvse commented May 24, 2016

@minggo I wanted to add that I tried the same thing with lower resolution sprites (the same sprites but for a lower res phone), and it was just as slow. But it seems to be related to Sprites: when I remove them and replace them with DrawNodes (simple square of the same dimensions), it's 60 FPS instead of 12 FPS. and I also ran the App Tune-up Kit from Qualcomm to see if the bottleneck is CPU or GPU bound for this app. Testing the same APK on the Nexus 5x, this tool tells me it's a CPU-bound issue. I wouldn't fully trust this simple tool however, but maybe it can help.

I also tried the same APK on a Galaxy S6 with Android 6.0.1, and on that one it was fast (60 FPS). So somehow on the Nexus 5x (which is otherwise a very fast phone) the FPS is very low.

I can share the project but I'm not sure you can reproduce the same on a Nexus 5, because this is quite a different device (I don't have one, so I couldn't try). Is it ok if I mail it to you?

Still - I wouldn't be surprised if many Cocos games suffer from this on the 5x (and probably other phones) because I'm only doing some very basic things. No animation, just displaying static sprites.

@minggo
Copy link
Contributor Author

minggo commented May 24, 2016

@niekvse thanks for testing. It is ok to mail me, thanks. I have test it on Nexus 5.

@niekvse
Copy link

niekvse commented May 24, 2016

@minggo I sent you the entire project (360MB or so) by wetransfer. You should get the email shortly. The big size is from Cocos - the actual code is only a few lines - but I thought it would be best to send everything, so you can reproduce it as accurately as possible.

Please DO NOT distribute this project anywhere online.

Let me know if you have any questions! I included screenshots of the app running on the Nexus 5x and on the HTC ONE M7, so you can see the different FPS numbers in the corner.

If you find out the cause of the issue - I'd love to hear it! Thanks!

@niekvse
Copy link

niekvse commented May 24, 2016

@minggo I solved the issue by more strategically adding my Nodes (I'm new to Cocos so I wasn't aware of the details of the batch algorithms). This does not completely explain why it was fast on the much older phone, but I have an idea.

I had 80 sprites and 80 drawnodes (background boxes), each drawnode containing one sprite (so they could be scaled and moved together, etc.) Apparently this meant that the sprite batching did not work, so the OpenGL calls were done like this: draw square 0 -> draw sprite 0 -> draw square 1 -> draw sprite 1, etc.

By first adding all DrawNodes and then adding all Sprites, all sprites could be batched, resulting in an FPS of 60 on the Nexus 5x.

So my conclusion is that the Nexus 5x somehow has a much higher overhead for the individual sprite draw calls than the older HTC (does it have to reload the texture each time? I wouldn't think so as I'm using a SpriteFrame).

So, the question remains why the OpenGL call overhead is so much higher on a much faster and better phone.

@Bilalmirza
Copy link

hey! @dumganhar
Was this issue fixed?

I downloaded v3.12 and had absolutely no effect on the performance. The v3.12 and v3.9 have the same results on different devices.

@dumganhar
Copy link

dumganhar commented Jul 11, 2016

@Bilalmirza, we only fixed the rendering problem. If your game has audio lags and please refer to #15875

@Bilalmirza
Copy link

My game has no audio yet

@Bilalmirza
Copy link

@dumganhar I removed all sounds and calls for sounds from my code a while back.

@dumganhar
Copy link

@Bilalmirza , could you send me a demo you're using for reproducing the issue?
And does the performance issue happen on all android devices?

@minggo
Copy link
Contributor Author

minggo commented Jul 11, 2016

@Bilalmirza it only fixed on some Android devices. Could you please create a new issue and describe it in detail? Thanks.

@Bilalmirza
Copy link

@minggo I'm really sorry for posting it here.
@dumganhar is it possible to talk on skype?

@dumganhar
Copy link

@Bilalmirza
Yep, added you.

@minggo
Copy link
Contributor Author

minggo commented Jul 14, 2016

Hi guys, @dumganhar fixed audio engine issue in this #15875. Would you please take a try and give some feedback? Thanks.

@maklaus
Copy link

maklaus commented Aug 7, 2016

Hey guys! Any chance to have v2 version of this fix?

@minggo
Copy link
Contributor Author

minggo commented Aug 8, 2016

@maklaus no, v2 doesn't use new audio engine.

@maklaus
Copy link

maklaus commented Aug 8, 2016

@minggo so this fps drop (i have it on galaxy tab4 only) is because of audio? But I tried to turn audio conpletely (not to call play methods) and still experience 30-35 fps

@maklaus
Copy link

maklaus commented Aug 8, 2016

I tried to comment //mapBuffers(); but in CCTextureAtlas.cpp (in v2 there is no Render.cpp) but its not fixed the fps (only fps stats dissapiars)

@minggo
Copy link
Contributor Author

minggo commented Aug 8, 2016

@maklaus audio engine is just one issue. And the rendering performance fixed can not be applied to v2, their rendering codes are different.

@maklaus
Copy link

maklaus commented Aug 8, 2016

@minggo ok, thanks for quick response!

@minggo
Copy link
Contributor Author

minggo commented Aug 8, 2016

@maklaus may be you can try as this comment

@maklaus
Copy link

maklaus commented Aug 8, 2016

Ive seen this fix but I have no experience to adjust it for v2.

@maklaus
Copy link

maklaus commented Aug 13, 2016

@minggo could you please adapt this solution for Cocos2d-x v2.2.6? I cant understand all these low-level functions at all =(

@Izzyjm
Copy link

Izzyjm commented Dec 12, 2016

is this issue fixed in the latest version of cocos2dx or do i have to go in the code and make the changes ? @minggo

@moonwith
Copy link

moonwith commented Feb 9, 2017

@minggo, galaxy tab4 still has this problem.I have commont "mapbuffer"

@minggo
Copy link
Contributor Author

minggo commented Feb 10, 2017

@moonwith this PR just fix the type of performance issue. So there may be other performance issue in galaxy tab4.

@IcarusLi
Copy link

cocos version: 3.11
Listview or ClippingNode that have stencil widgets will make Andriod running slowly.
I test this on MT6753(or other mediatek- CPU)
Every ClippingNode or Listview will reduce about 5 fps .
I had make some changed on RenderingCPP,but I don't think it affect to this.

@IcarusLi
Copy link

IcarusLi commented Feb 16, 2017


I had solved this issues !
version 3.11.1

CCClippingNode.cpp line 59, " new StencilStateManager()"
...为ClippingNode创建了一个StencilStateManager
ClippingNode::visit()
.....然后在visit函数里面调研到onBeforVisit函数
StencilStateManager::onBeforVisit()
...这个函数干了什么呢?----drawFullScreenQuadClearStencil
this onBeforVisit() function will do this:
/////`` drawFullScreenQuadClearStencil() ````/////

I just write another drawSolidRect( srcPoint,dstPoint) funcions ;
...然后我写了一个局部操作的函数,把下面的值扔进去
srcPoint = convertToWorld(0.f,0.f)
dstPoint = covertToWorld(_contentSize,width,_contentSize.height)

FINISHED!
..提升了超级多帧率,特别是那种比较小的listview/clipping node
It can works well on Any Android Phones.hhhhhhaaaaa
when you need some small ClippingNode it is usefully!
Now I can running @30fps for my game now,before i did it, it's hard to running @15fps!

@sedapsfognik
Copy link

sedapsfognik commented Mar 28, 2017

Hello, guys, did you fix this problem?
Is this fix applied to cocos which we use in Cocos Creator?
I faced a problem in a js/html5 game created in Cocos Creator: 60fps on iOS on both iPhone 5s and iPhone 6s devices.
And 10fps on HTC One X and Samsung Edge 7 with exactly the same conditions.

Here is the screen:

https://gyazo.com/835a8b55b2a48c04934bb0ea3554e69f

It is after drawing ~20 sprites without any logic, moving objects or animations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests