I had it all worked out.
In testing a new code change, I found it was about twenty times slower than the existing code. I discovered this fact towards the end of the day, so even though I wrapped up my mind kept spinning on the problem. Theories appeared and disappeared, and were deemed plausible or dismissed by my subconscious.
When I sat down to work the next morning, I could see the entire day, maybe even the remaining weeks of the project, ahead of me. I knew exactly what I was going to test, exactly what the result would be, and had the solution elegantly coded in my mind. The solution would surely apply neatly across all of the other code that needed this functionality.
I had it all worked out.
But as you probably guessed, after I compiled my brilliant code that morning performance remained twenty times slower.
Sometimes we craft the solution before we know the problem. I think that’s especially true when it comes to performance.
This has happened to me more than once, but I had to learn the lesson again: you will never guess the performance bottleneck. You have to measure. And then measure again, the same way, until you know you can trust the measurement.
Then, and only then, solve the problem.