Friday, June 20, 2008

Less code

One dimension that I hadn't explored fully in my attempts at Wide Finding was that of program size. My primary concern so far has been algorithmic design and performance. Starting with around 340 lines of code in 5 separate source files, I removed all trace of reusability, and some of the configurability, and what resulted was one file (WideFinder2d.scala) containing just 196 lines including whitespace, comments, etc.

It's not as reusable. What was formerly a general purpose Sorter is now just an embedded sort function, and what was formerly a Matcher is now just an embedded eachMatch function. The configurability went mostly unused, so I just yanked that. In terms of performance, this version did pretty well:

real    14:57.6
user  7:18:11.7
sys     10:01.1

The difference in performance is most likely due to the rearranging of code to avoid duplication, and rehashing as the code no longer preallocates entries in the referrer and clients tables. The resulting code is here.

No comments:

Post a Comment