Optimizing Memory Layout with Vectors

Memoization has gotten us quite far along the path of building a sufficiently fast spellchecker, but we’re still not fast enough. In this section, we’ll look at another factor that can impact the performance of our programs: the shape of our data structures and the way we store and access memory in our programs.

You saw in the last section that when we started using ST to memoize a map of results, we ended up taking a significant performance penalty. It turns out that when we’re trying to get the best performance out of our applications, there are a few factors we need to think about beyond algorithmic complexity:

  • Avoiding indirection by having too many thunks that need to be evaluated for any particular ...

Get Effective Haskell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.