Transformagician – Performance Optimization

Posted by
April 23rd, 2016 3:16 am

The jam is over, the entry turned out great and the WebGL build (which most people are going to play) runs quite badly. What to do? Optimize!

Identifying the problem

When trying to improve performance you should always go for the elephant in the room. In most cases (including this one) taming the alpha male is enough. Run the profiler on the target build and see what is up (milliseconds) and what is down (framerate!). Let’s look at the rendering performance of the following scene.

Image 1: Benchmark scene

Figure 1: Rendering performance in Unity editor

Not bad! The deferred renderer does a pretty good job at batching drawcalls.

Figure 2: Rendering performance in WebGL build

Very bad! The WebGL build seems to fall back to forward rendering before a deferred lighting pass. Maybe this is why the batching is botched, I’m not quite sure, but there most certainly is a drawcall problem.

Solving the problem

One solution immediately springs to mind: Mesh.CombineMeshes. After some modifications the script works like a dream.

The walls in the scene are combined into a single mesh and the floors into another. As long as all the meshes share the same material there will be no trouble and the combined mesh looks just like a bunch of individual objects.

The only difference being a drastic reduction in draw calls. Let’s see just how drastic we’re talking about here:

Figure 3: Rendering performance in editor (with MeshCombine)

Mere three times faster… I think we can do better.

Figure 4: Rendering performance in WebGL build (with MeshCombine)

Fifteen times faster! I rest my case.

Conclusion

Use the profiler, identify the worst offender, smite it and rejoice. There are further optimization I could do, but why bother. At this point it’s already an effort in diminishing returns.

Getting less than 60 frames per second? Time to look in the mirror and get to work!

Tags: , , , , ,


Leave a Reply

You must be logged in to post a comment.

[cache: storing page]