Answer the question
In order to leave comments, you need to log in
How to ensure the speed of a Java program?
Good afternoon everyone, the question is a little theoretical, but still.
I started learning Java, specifically programming in android studio.
The bottom line is that having on hand not the weakest Samsung M31 device, my simple game in terms of graphics and calculations is already starting to slow down.
At the same time, the CPU load of the phone is at the level of 20% and the RAM is used at all about 100 MB.
In order not to delve into the code, I’ll just say that at the moment I’m rendering everything through Layout, approximately 128 objects each iteration, all objects for rendering are stored in two arrays of the ArrayList type, 64 objects each.
But it seems to me that the problem is that all the code is executed in one thread, and the more different calculations, the more time it takes for each iteration of the thread.
Do I understand correctly that you can create two or more threads, and this will speed up the program?
What can be done to speed up the program, and where can I read?
I will be grateful for the answer.
Answer the question
In order to leave comments, you need to log in
Mobile hardware is very slow, and the rest, it’s not so easy to display graphics in software, so you need to work with a gpu accelerator. By the way, even in this case, the wrong implementation will put any iron.
For example, transparent rectangular sprites cannot overlap each other indefinitely, and we are talking about units - a maximum of tens of objects.
Either take a ready-made engine or study Opengl ES and shaders (miniature subroutines running on gpu with a large number of threads, hundreds or even thousands)
Good afternoon!
If you are interested in developing games on Android & iOS, then you should start not with Java, but with C # (for example, Unity) or C ++ (for example, the engine is Unreal Engine)
But if you decide to write games specifically in Java, then look aside ready-made engines or frameworks.
https://libgdx.badlogicgames.com/
https://www.lwjgl.org/
https://jmonkeyengine.org/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question