[Haskell-cafe] Optimizing a title matcher

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Tue Sep 26 22:49:41 EDT 2006

Lyle Kopnicky wrote:
> data TextTable s = TextTable { tableFields :: ![s],
>                                keyFieldIndex :: !Int,
>                                tableRecords :: !(HashTable s (Array Int s)) }

> listRecords :: AbsString s => TextTable s -> IO [TextRecord s]
> listRecords (TextTable fields _ records) = do
>   keyRecs <- HT.toList records
>   return $ map (fromList . zip fields . elems . snd) keyRecs

Doing fromList again and again can't be good. Why don't you make
tableFields a map that maps names to array indices? Then you can just
pass the bare arrays along, and the later lookups will be cheaper, too.

Now due to lazyness this will probably be evaluated in matchscore,
because before that the resulting Map isn't used. Which is exactly where
you said a lot (most?) of the time is spent.

Another thing is that you should compile your code with -O, but I guess
you are already doing that.

Hope this helps,


More information about the Haskell-Cafe mailing list