Ventures of an ex indie game developer

Jitter... bug?

Devised a nifty little feature which really did a lot for my game engine. At first it was more of something I wanted to do at some point, but the results turned out terrific! What I did was a “call graph time measurer” combined with some gay presentation. This allowed me to find performance bottlenecks far easier than any tool I’ve used before. Truth to be told, I haven’t used VTune or DevPartner’s Performance Analyzer for nine years, but I still think the most important features of my findings are quite valuable. And when using the tool I quickly got the frame rate up by ten times (from a jerky 130 FPS to smooth 1200 FPS+ in debug compile) on a basic setup with some graphics, physics, IO and so forth.

The “call graph time measurer”, hereafter called ScopeTimer, is a simple fire-and-forget timer, much like the scoped mutex in boost. The constructor parameter to the ScopeTimer is a data container which knows about some basic stuff like start time, delta time, and also has a name and knowledge of parent and children. I keep all data thread safe by thread local storage. Around the ScopeTimer I added a convenience macro like so:

#define MEASURE_SCOPE(name) \
static const string _name_(strutil::fmt(#name ";" __FILE__ ";%i", __LINE__)); \
static const std::hash _hasher_; \
static const size_t _hash_ = (_hasher_)(_name_); \
ScopeTimer _timer_(ScopeData::insert(_name_, _hash_));


When all the data is collected for a frame I can unfold the call tree for each thread I’m interested in, and print it out. Printing is an ok solution if all you have access to is a text console (i.e. server side). On the graphical side I added a cheeky renderer which takes the times for the scopes and plots them as line segments each frame, with a history of 100 frames or so. The result is a live feed on what scope is causing delays:


The pink part is "waiting for physics to finish this frame" and purple part is the graph rendering itself (highly unoptimized) and the green part is "sleeping until frame time over". The black graph just below is physics times.

I also added a printout of all the names that appear in the call graph, in the same color as their respective line segment, and what file/line they where declared on. Jitter detection is now a walk in the park, along with what's causing it.

Although the idea was easy enough it still took me a couple of days+nights to get everything set up - but I would definitely recommend it!

Oops: 07:03. Time to go to bed. Unemployment is good again! ;)

About the author

Mitt foto
Gothenburg, Sweden