How do I configure intermittent delays / slowdowns for optimization in Java? (see example inside)

I am developing an action-platformer game using Java and have recently finished AI coding for an enemy unit. I began to notice that at certain points in the game he slowed down and lagged before returning to normal life. See an example in this video. The lagging part is somewhere in the middle of the video and annotated, so you will not miss it:

LoGaP 06/06/2013 on YouTube

I would suggest that some code that he is trying to execute becomes a bottleneck. Is this a typical symptom of a memory problem or a CPU problem?

More importantly, whatโ€™s best in this case is to determine what the problem code is, so that I can analyze how to optimize it? The only optimization tool I used only for Java was jvisualvm, and I used it for a while. Will this be done in this scenario?

+4
source share
1 answer

A common problem with profiling is that you have a method that usually runs at an acceptable time, but from time to time becomes a bottleneck.

Profiling the entire run will most likely not help you, as one slow call will be drowned out by all other regular calls.

In JProfiler, you can mark a method so that the exception of exceptional methods is stored separately, and you can examine the slowest operations in detail, you can use the statistics view of the method to see the distribution of calls and mark them to record the exceptional method:

enter image description here

In the call tree view, the slowest calls will be marked with the suffix [exclusive run], and you can examine their call tree individually:

enter image description here

Disclaimer: My company is developing JProfiler.

+1
source

Source: https://habr.com/ru/post/1486171/


All Articles