Twitter  Facebook  YouTube  E-Mail  RSS
The One Man MMO Project
The story of a lone developer's quest to build an online world :: MMO programming, design, and industry commentary
Faster Faster
By Robert Basler on 2018-12-03 02:54:47
Homepage: onemanmmo.com email:one at onemanmmo dot com

Vermillion Hardship is the eighth and final biome for Bold New World. I finished up most of the work for it last Monday, the rock formations are looking great, texturing looks really sharp, and I made several new microprops. I'm finally starting to feel comfortable making my own art in Blender. The last thing left to do is to find some new larger decorations since I removed all of the existing ones.

While I was thinking about that, I started on my QA pass. It didn't take long to find a big problem. The ability to move around Miranda smoothly has always been a huge priority for me, and at the start of the week, movement was very jerky due to an inconsistent frame rate. Luckily, optimization is just about my favourite thing to do as a programmer. You don't have to figure out how to make something new, you just have to find out what's slow, and then puzzle out how to make it faster. Oftentimes, much, much faster. So I turned on Miranda's frame profiler and found several functions which were sometimes taking a very long time to execute (as long as 250ms - a whole frame usually takes just 16ms.)

The cause of the 250ms delay was Miranda's model loader. Miranda loads 3D models on a worker thread so that doesn't affect framerate, but once they are loaded they have to be put into a tree for rendering which is done on the render thread. It turns out that occasionally a whole bunch of models finished loading at the exact same time which caused that frame to be very, very late. The fix was to simply put a timer on the render thread model loading code so that it can't run for more than 5ms. Anything that doesn't get done immediately when it comes in, gets done over the next few frames until all the models are processed.

The next delay was 180ms spent compiling the material script for each block of microprops. It turns out that too was running on the render thread, so I moved it to the already-existing worker thread that builds all the renderables for the props, easy peasy.

Next up was a 175ms spike processing compiled material scripts. Every 3D model in the game has a list of materials associated with it. Materials control the renderer to tell it how to render each and every triangle that makes up a 3D model. Each material has a set of passes, each pass has a set of shaders. Like the model loader, it happened that occasionally a lot of new material lists were queued up for processing on a single frame. The first step was to limit the number of those processed each frame, and that got the time down to about 75ms - still far too much. Miranda's renderer processes a full material list at a go and one of them was simply too long. When Miranda loads a new set of shaders for a pass, it checks to see if it has already loaded that particular set of shaders before. With all of Miranda's new art, there are far more shaders than there used to be, and the code to check for an existing shader got called a lot of times which was where the problem lay. The shader comparison function itself is pretty short, so first I removed a couple of memory allocations and simplified some string handling, but that only got me a few milliseconds. Miranda was doing a full source code comparison of the shaders, so next up was to change that to a comparision of a cryptographic hash of the source code. That got it down to about 35ms at the end of Friday.

So there's still work to do on that one, plus probably another half dozen to look at in the 30-40ms range which I'm hoping won't be quite so difficult. But even with just those improvements, by Friday afternoon movement was looking a whole lot better. Pretty slick in fact.

New Comment

Cookie Warning

We were unable to retrieve our cookie from your web browser. If pressing F5 once to reload this page does not get rid of this message, please read this to learn more.

You will not be able to post until you resolve this problem.

Comment (You can use HTML, but please double-check web link URLs and HTML tags!)
Your Name
Homepage (optional, don't include http://)
Email (optional, but automatically spam protected so please do)
What is four plus three? (What's this?)

  Admin Log In



[The Imperial Realm :: Miranda] [Blog] [Gallery] [About]
Terms Of Use & Privacy Policy