by mjuarez · 2mo ago · 0 comments
So I took a look for about 30 mins figuring out the code (I don't know SPSS or R), and it turns out she was doing some calculations that were identical for every single line, regardless of that line's fields. So I pre-calculated a few things, prior to starting the per-record-loop, and then just used the pre-calculated values every time. After that, every run took less than 5 minutes. She's amazing at math and economics, but optimizing low-level code is not something she has done in the past.
The main fix was not making it hideously IO bound, as not only was it loading every image multiple times, it was then grinding away in swap as we’re talking tens of gigabytes of raw image data, in an era when 1gb of ram was a lot - and then making it spiral out from the last known location of the object of interest rather than brute-forcing it. My solution wasn’t even optimal, as it was literally just an afternoon of tooling around as a favour.