Categories
Uncategorized

Botched Keymapper = wasted half day

I did some performance analysis today and found that the freaking keymapper was taking 28% of the total CPU time! It even took longer than the render cycle. The keymapper was one of the first tasks I gave out, about 6 months ago, to a junior programmer. It’s supposed to load an XML of strings […]

I did some performance analysis today and found that the freaking keymapper was taking 28% of the total CPU time! It even took longer than the render cycle.

The keymapper was one of the first tasks I gave out, about 6 months ago, to a junior programmer. It’s supposed to load an XML of strings of actions, and bindings. It would map the strings to numbers, and create an association between the two. So that given a list of pressed keys I can get the corresponding actions, etc.

The main problems are dealing with multiple keys to trigger a single action, actions that take multiple keys to trigger, and how to handle the situation where more than one action is possible given multiple keys.

The original programmer loaded the XML files and just kept them in memory. He then did string lookups only, not using the numerical equivalents like I told him to. Worse, these were XML based string lookups, so it would have to parse the whole XML file to look up a particular binding, then a particular string. Worse, in order to handle the case with duplicate mappings, he would scan the whole list again. So it’s slow * slow * slow.

On top of that he didn’t handle the situation with multiple bindings for a given action, so you couldn’t do left control OR right control to fire. Only one or the other. And he didn’t correctly handle the situation with multiple keys to multiple actions, so if I pressed a key combo to trigger an action, and that combo included other actions, those other actions would trigger too.

Basically he made an O(1) operation (if you’re smart about it), or an O(n) operation (if you’re not), into an O(n^3) operation.

I rewrote it. I got each call from 160.8 nanoseconds to 4.5 nanoseconds, has the two features his didn’t, and I did it in half a day, where he took 3 days.

Incidentally, it was another bad programmer that wrote the XML lookup to begin with. He also didn’t follow my instructions on how to do it efficiently. Sort of bad programmer squared.

2 replies on “Botched Keymapper = wasted half day”

Wow, thats a lot of incompetence going around
So do you get your money back since the hired programmers didn’t code to spec?

Leave a Reply

Your email address will not be published. Required fields are marked *