bitwix

Tangential comments about Software Development

Wednesday, August 05, 2015

Nine seconds on efficiency

I worry about efficiency when my code is not fast enough - I don't design it in.

My Japanese language practice iPhone app was taking 12 seconds to load. There's a fair amount of text processing to turn CHOTTO MATTE KUDASAI into ちょつと まつて ください and my app now has 700 words and 200 phrases. So text processing was the culprit.

The afternoon started with a quick win. There were two hard-coded dictionaries which I moved from inside the class to outside it. That is, from

class RomToHira {
  var hiragana_dictionary : [String:String] = [ "A" : "あ", ... ]
  var katakana_dictionary : [String:String] = [ "A"  : "ア", ... ]
  func ToJapanese( string : String ) -> String {
to
var hiragana_dictionary : [String:String] = [ "A" : "あ", ... ]
var katakana_dictionary : [String:String] = [ "A"  : "ア", ... ]
class RomToHira {
  func ToJapanese( string : String ) -> String {

12 seconds fell to 3 seconds, just like that. 4x speed improvement, and no threat to the code - no wizard-like complexity.

I then tried different things to improve further, like replacing String with NSString. Nothing made it any better, some of the changes made it far worse - unichars aren't my thing. I tidied up the code, removing dead stuff and making functions private and class, then went home.

So I stopped with a 4x improvement, a 3-second load time. That's not bad. わるくない です