I’ve given up trying to keep track of the daily moves for the Going 9 AL-only league at my site, but I am at least trying to track who is owned/unowned there. And I noticed that when I loaded the LeagueHome page, it would first show the standings, pause for what seemed like about a second, and then paint the rest of the page.
Other leagues I’m hosting don’t do that – they seem to paint the full league in one shot. The Going 9 page, though, had a noticeable, and repeatable, pause. What was the issue?
I ran the code generating the page in a profiler and found one single function call was taking about 1.7 seconds. That function was attempting to take a league’s configuration and generate a list of all possible valid lineup configurations. Most fantasy leagues use both corner (1B or 3B) and middle (2B or SS) slots, but some don’t distinguish among pitchers, and others also have overall utility slots. Also, since my site now supports separate outfield positions (LF, RF, or CF) this can increase the number. And it turns out that was the issue: the Going 9 configuration leads to nearly 160,000 possible valid positional lineup configurations, if your positions can be SP, RP, or P for pitchers, and 1B, 2B, 3B, SS, C, LF, RF, CF, or OF for batters.
I try to validate if your lineup is legal, and warn you if it’s not on the LeagueHome page. The Lineup page, which also checks the validity of your lineup, had similar slowness. But it turns out that over a year ago, I had changed how I validate lineups, so that I no longer used the list of possible valid lineups. So I was making a function call I didn’t need, and it was, in this case at least, visibly slowing performance. So the solution was to remove the call entirely, and since nothing else called that code, I could remove that code also, leaving a somewhat smaller code base.
Sometimes you’re productive, not when writing new code, but removing old code. Yet another instance of Antoine de Saint Exupery’s quote that perfection in design is achieved not when there’s nothing left to add, but when there’s nothing left to take away.