![]() Also, often memory allocation is correlated with runtime, so this helps runtime performance as well :) This can help you discover which functions are allocating a lot of memory, and this is a good indicator of where you can improve. If you’re using Android Studio, a relatively straightforward method of getting started is by running the Android profiler, clicking ‘memory’, and recording Java/Kotlin allocations. Usually when talking about performance we mean ‘runtime’, but if you’re using LibGDX that probably means you’re aiming for multi-platform, and lots of people have low-end phones with limited memory, making this an important aspect as well. Try out memory performance at least once, for low-hanging fruit Why? You’ll know you won when you start seeing glClear taking a long amount of time - that means you’ve reached the maximum amount of FPS and glClear is purposefully wasting time throttling the framerate :) Memory Performance What to do? Your profiler will now both segregate this class’s draw() functions from the rest, and tell you that it’s this class’s function.Īlso as a sidenote - Group()’s isTransform is set to true by default, and calculating the transformation also takes a non-negligible amount of time, so as a rule of thumb I set all Group isTransform to false unless otherwise necessary. Split heavy data gathering belongs to another thread, then sync the UI in a.Separate heavy actions to a different thread What to do? Is this really a performance tip? Not as such, but it made such a difference I couldn’t not add it to the list. So much fluff disappeared, functions were easy to pass around, sequences were simple, and the null typechecking saved me from more silly errors than I can count. The difference was astounding - about 20% less lines of code. I started the project using Java, and after about a year of work migrated to Kotlin. You can mouseover every individual part to see when and where time was a-wastin’ For new projects, Kotlin saves headaches Whatever your profiler, I recommend using a flame graph to view the results - for me, the instant readability of the flame graph and being able to drilldown instantly while keeping perspective of the entire run made this an amazing tool! I personally use Android Studio’s Android performance profiler for both CPU and Memory. Who says you even have a performance problem? Who says you’re optimizing the right thing? Without data, you won’t be able to tell if you’ve made things better or worse. Rule 0 - Don’t try and guess your bottlenecks ![]() ![]() General coding performance - do less, exit faster, and cache results.Add helper functions in subclasses for performance, profiling and debugging.Separate heavy actions to a different thread.For new projects, Kotlin saves headaches.Don’t try and guess your bottlenecks - use a performance profiler.I’ll start off with a bunch of pointers so you can skip right to the part that interests you: During the 5+ years I’ve been working on the app, I’ve learnt a lot of things that would have helped me earlier in my journey, and this is a summary of those points :) I’m the developer of Unciv, an Android/Desktop LibGDX application. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |