New Year’s Eve!

Ok, so I’m really boring, I’m not having fun with the rest of the guys on new year. Instead, I’m programming… forever alone!

I’ve not progressed much in terms of the mechanics or content today. But I did find out a massive CPU leak, it’s literally making my computer turn the fan on (which is impressive on my Air, it’s generally cool to the touch).

It sits on about 35% CPU in LoadingState, which is obscenely high considering it’s only writing out a static ”Loading…” for a good 4.9 seconds. And 99-100% in StartState, granted, it does write out more than DOUBLE the amount of text. Jokes aside, after profiling the process(oh, glorious Xcode), I can see that at least 75% av the CPU time comes from Mach_Absolute_Time, a function call to determine elapsed time (from when? Not sure, doesn’t seem to be documented).

This function is called by SDL_Timer to determine weather or not the time has passed on the timer. SDL_Timers can run on separate threads from the main program, and it doesn’t seem to have any limit to how often it can check for the time. Considering that Mach_Absolute_Time is accurate down to nanoseconds, 100 000 times greater accuracy than milliseconds, it’s probably calling every nanosecond to see if it is a match, which obviously is pointless since the timers accuracy is in milliseconds…

I have tested the code on Windows too, while considerably less consuming, it still sits on 17-20%. This is on a gaming computer. You know, the ones that can play the latest games on the same percentage (or less). This game in it’s current state shouldn’t even amount to 1% (it’s basically just waiting for human input or timers).

Conclusion: Find an alternative to SDL_Timer. It can’t be the right choice if it cause that much CPU time to be wasted.