Seeking Advice on Performance Profiling

Anything libgdx related goes here!

Seeking Advice on Performance Profiling

Postby JohnRoy » Fri Feb 07, 2020 4:10 pm

Hi Everyone,

I'm doing my first project using Libgdx and I could use some advice on where to look for my performance issue.

What I have:
In the render method (com.badlogic.gdx.Screen.render()) I render a couple of sprites (AtlasRegions) on the screen using a SpriteBatch with a camera.combined projection matrix. I do one call of begin/end of the SpriteBatch for each render cycle. I put some effort in optimizing the code in the render loop. Everything shows up nicely so far. It's a turn-based game, hence beside the render loop there is nothing happening except for one thread waiting for user input.

My config looks like this:
Code: Select all
LwjglApplicationConfiguration cfg = new LwjglApplicationConfiguration();
      cfg.title = "Libgdx Game";
      cfg.useGL30 = false;
      cfg.width = 800;
      cfg.height = 480;

The problem:
Even in the "idle-state", that is the game is waiting for user input, I only get somewhat between 20 and 40 FPS with the LwjglApplication version on my Macbook pro, which is much less that I expected. Furthermore, the game seems to slow down the entire OS. It's hardly possible to use the system for other stuff, when the game is running.

What I did for profiling so far:
I used the GLProfiler to analyze the number of draw calls and texture bindings. It is usually about 10 texture bindings and draw calls. (150 opengl calls)
I did some time measurements around my render code. It shows that one cycle of my render code takes either 0 or 1 milliseconds, while the time in-between the calls of com.badlogic.gdx.Screen.render() is 20 to 40 msec.
I used Visual VM to find the problem. All I see is lot of activity on org.lwjgl.MacOSXContextImplementation.nSwapBuffers[native] in the sampler. In the profiler all I find is I have to admit that I don't know what to think of that.
I also started the game on an Android device, but its even slower there.

What I''d like to know:
Is it reasonable that I can only get 40 fps on a MacBook pro with i7 ? I thought, it should run much faster.
Does anyone have a hint where eIse to look for tracking down the problem?

Thank you very much!
Posts: 3
Joined: Sun Dec 22, 2019 9:35 am

Re: Seeking Advice on Performance Profiling

Postby GQuark » Sun Feb 09, 2020 9:14 am


I'm coding complex 2D & 3D displays in LibGDX and I never seen something less than 60 fps on a MacBook pro (2015) & 50 fps on high end iPhones. However, it could be very slow on old android phones. So to answer the first part of your question, I guess there is something wrong with your code because 20-40 fps on a MacBook pro is extremely unusual
Posts: 9
Joined: Mon Nov 19, 2018 7:21 pm

Re: Seeking Advice on Performance Profiling

Postby JohnRoy » Sun Feb 09, 2020 10:39 am

thanks for your reply. So I can have hope to find the problem and get the game faster. What I'd like know about the libgdx (and opengl) rendering engine: When my rendering code (render-method) runs slow, the game of course can only be slow - clear so far. But if my rendering code is running fast itself, can I still have potentially bad/wrong things done there slowing down whats happening between the render-calls?
Posts: 3
Joined: Sun Dec 22, 2019 9:35 am

Re: Seeking Advice on Performance Profiling

Postby JohnRoy » Sun Feb 09, 2020 4:01 pm

I just profiled the situation once more. With 26 OpenGL draw calls I'm down to 17 FPS on my Macbook Pro 2017 and the system is more or less completely frozen, while only showing 5% CPU usage for my game application.

Could anyone suggest an open source libgdx 2D game, that is known to run smooth, that I could check out and build? I could then check, whether that runs fine on my machine and if so, I could work out the differences step-by-step. Thanks.
Posts: 3
Joined: Sun Dec 22, 2019 9:35 am

Re: Seeking Advice on Performance Profiling

Postby yobowargames » Mon Feb 10, 2020 6:40 pm

Why don't you post the code that you have in the rendering method? I use a Mac all the time doing far more in the rendering cycle than you mention and don't see any slow down on it. Have you looked at what else it using CPU on your mac at that time?
Posts: 15
Joined: Sat Oct 27, 2018 4:25 pm

Re: Seeking Advice on Performance Profiling

Postby QuiIIraven » Thu Feb 13, 2020 3:14 am

What I find confusing is that you say you render atlas regions. So I guess all of them are in the same atlas and therefore same texture? If so then you should actually only have one draw call and one texture binding.

But hard to say without any code.

If you need examples you can check out e.g. my github. Mystic Garden, Tetrolix or Quilly jumper. All of them run smoothly on my Samsung S8
Posts: 98
Joined: Sat Jun 02, 2018 4:59 pm

Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot] and 1 guest