As always, I suspected database access. I tidied it up, and got no improvement. Was I a victim of success, that we had so many users that I needed to split the database into shards, like the old London phone book (volumes A-D etc)?
Thankfully, I took my time to address this, thinking through other possible problems. When I got around to going through the code, profiling functions, I found a sorting algorithm I had written one day when I couldn't be bothered to implement an IComparer bit of code. To add insult to injury, I found that later in the process a better sorting method was used, so the bad algorithm served no purpose whatsoever. So I started commenting out code:
public static ListFetchForTaxYear(KwDataSet ds, int year, string aorc) { Listresult = new List foreach (Rent r in FetchNotDeleted(ds)) { if (r.TaxYear(aorc) == year) { result.Add(r); //int idx = FindInsertPosition(result, r); //if (idx >= 0) // result.Insert(idx, r); //else // result.Add(r); } } return result; }();
I asked the user who'd reported the problem, and she responded "it is so speedy I didn't dare blink". So that's good.
Lessons learned? It's not always the database. Suspect your old code, and be ready to change it. A small change may well be enough. Take time to choose a course of action. Don't write order-n-squared algorithms.