Optimization, Logic-wise

On wiki, there is page on optimization, but it is mainly of optimization of rendering (batch factory). But rendering is smallest part of game. I’d like to ask about tips on how to optimize game logic - after all, update loop takes time too and if it is badly written, it can significantly decrease FPS.

The first optimization is to remember the old adage about pre-optimizations :smiley:

This question depends entirely on what your update loop is doing, but I would say that a smart use of the engines features - like AppStates - goes a long way by allowing for your update logic to be broken down in a modular fashion. From there it is a matter of only keeping states active when they need to be performing their task.

Allocating memory in the update loop, constantly creating new objects on the heap, and other potentially ‘lengthy’ operations can also become issues but there is no substitute for good design and lots of time with a profiler


Well and depending on the type of animations multithreading. for example models can be preloaded in background and then enqued to be attached, instead of blocking the update loop while the hdd heads moves (even today average is somewhat around 10-20ms a model with 4 texutures without processing could lead to 100ms this way, and a 100ms lag is noticeable) . All depends on what the game does and what problem you exactly are having.

Good design is usually the best optimisation.

1 Like


the best way to optimize is to use Profiler plugin in JME Platform(Netbins based). This should show everything(i mean it show you what need to be changed to work better).

You can activate it in JME Platform configuration - plugins tab.

BTW: as was said, you should also write your modules basing on AbstractAppState

1 Like

As most people state here… Experience is the best assurance that you write effective and performant code. The profiler can be very dangerous in the hands of a newbie as you have to understand its output. Hunting performance improvements in the wrong areas just takes huge amounts of time. This means that you’ll inevitably come to write some “inefficient” code at some point and then you’ll have to research on how that bit can be improved, adding that knowledge to your arsenal.

1 Like

Well, I am actually using AppStates, but more for break my game logically than for performance. I can’t even imagine how my code would look like, if I wouldn’t use it (it’s a mess anyway). Normen, and I know that experience is best solution for all problems one can face, but it is the only thing I don’t have right now. That’s why I asked for tips. Also when I used profiler, it generated some weird selfsample(randomnumbers).npss file in /tmp with which I don’t know what to do

I haven’t used the SDK/NetBeans profiler, but VisualVM is quite nice.

If you’re already using AppStates then you’re on the right path. Consider if they all need to be enabled on every update. Of course, if you have no proof that your update loops are actually slowing anything down then this is a bit of a moot point :slight_smile:

@sbook said:
I haven't used the SDK/NetBeans profiler, but VisualVM is quite nice.

.. netbeans uses the default JDK profiler which is VisualVM :)

So that’s where that Oracle branded VisualVM.app came from in OS X… It suddenly feels dirty and tainted :p. I didn’t realize they were stuffing it in with the JDK now

They do like jdk 1.5 already?