Skip to content

Optimizing Your Game Using Statistics

When you create a SimpleApplication, you see the default StatsView and FpsView in the left corner. The StatsView displays object statistics that are used during development, for example for debugging and optimization. Below the StatsView is the FpsView that displays the frames that jMonkeyEngine can render per second.

The main use case of these statistics is to find out why the application may be running slow and where to start fixing the performance.

The StatsView + FpsView look like this example:

FrameBuffers (M) = 2
FrameBuffers (F) = 2
FrameBuffers (S) = 2
Textures (M) = 7
Textures (F) = 3
Textures (S) = 3
Shaders (M) = 6
Shaders (F) = 3
Shaders (S) = 4
Objects = 24
Uniforms = 31
Triangles = 582
Vertices = 1148
Frames per Second: 30

On/Off

You switch the StatsView on an off in the simpleInitApp() method by setting a boolean:

setDisplayFps(false);       // to hide the FPS
setDisplayStatView(false);  // to hide the statistics

Terminology

Types of items counted:

  • FrameBuffers: Total number of rendering surfaces used for off-screen rendering and render-to-texture functionality.

  • Textures: Total number of distinct textures used in the scene.

  • Shaders: Total number of shaders used for effects (shading, blur, lighting, glow, etc).

  • Objects: Total number of objects in the OpenGL pipeline. That is, objects attached to the rootNode and guiNode, etc.

  • Uniforms: Total number of shader uniforms. Uniforms are predefined variables used as parameters in shader calculations, containing data such as matrices, vectors, time, and colors.

  • Triangles: Total number of triangles (faces) of the meshes of all objects.

  • Vertices: Total number of vertices (corner points) of the meshes of all the objects.

Types of statistics:

  • (M) = Memory – Number of items currently in OpenGL memory.

  • *(F) = Frame * – Number of items used by current frame (visible).

  • (S) = Switches – Number of items that were state switched in the last frame.

The StatsView does not include any Physics statistics.

How to Interpret the FPS when Optimizing

FPS reports how many frames are rendered per second. Choose a frame-time target for your game and devices; low FPS can come from CPU work, GPU work, synchronization, memory pressure or other causes. Use profiling to identify the bottleneck before deciding what to optimize.

If your application grows more and more sluggish, deactivate or decrease one feature set at a time: Deactivate drop shadows, physics, anti-aliasing… Try fewer light sources, fewer NPCs, fewer samples in spheres (i.e. less smooth spheres). Temporarily replace the scene (or parts of it) with a simpler test scene to check whether the scene has to many triangles, etc.

Keep an eye on FPS and the StatsView and find out which element has the biggest impact on performance. This is where you start optimizing.

How to Interpret The Statistics

Important

The statistics overlay itself contributes rendering work. For small comparisons, measure a baseline and use the same settings in both runs.

What do you want to avoid?

  1. Framebuffers: Render targets can be used by post-processing, shadows and other rendering features. Compare configurations and profile the passes rather than assuming the count should be zero.

  2. Objects and batches: Compare draw and state-change counts between representative scenes. Batching or instancing can help in suitable cases, but the useful budget depends on the renderer and hardware.

  3. Triangles and vertices: High geometry counts can contribute to GPU cost. Test level-of-detail settings and compare models on the slowest target device; there is no universal vertex limit.

  4. Are any counts constantly increasing right before the game slows down or runs out of memory? Check whether you are accidentally adding objects in a loop, instead of only once.

  5. Verify that the numbers are plausible. If you think you generated a test scene out of “a few” boxes, but the StatsView shows ten thousands of triangles, then you probably have extra objects out of sight somewhere (due to barely visible materials, overlapping with other objects, scaled too big or too small to see, etc).

    • A box has 12 triangles, but its vertex count depends on how the mesh represents face normals and texture coordinates.

    • Terrains, models and spheres have higher counts, depending on their size and Level of Detail (LOD). A high-poly model looks pretty in Blender, but you must find a lower-poly, low-LOD compromise if you want several large objects in one scene!

  6. If S (objects being switched) are high compared to F (objects used), then you use or generate too many different Materials (etc). You are unnecessarily forcing jME to re-load and re-bind objects (= Switches), which is bad for performance. Also if you have many transparent materials in your scene, this results in more switches, and you should use fewer transparent materials.

  7. If the M values (objects in memory) are high compared to F (objects used), that means a lot more GL objects are kept in memory than are actually used. This can happen in large scenes with many materials. Inspect asset lifetimes and loading behavior; detaching a spatial alone does not necessarily release its GPU resources.

Set budgets for frame time, memory and loading for the devices you support. Compare representative workloads and use CPU and GPU profiling alongside these counters; a single count or FPS value does not identify the bottleneck by itself.

See also: