Feb 15 2010
Lesson learned
I had a problem last week. I had refactored TasksApp to be wholly object-oriented, and had just finished the second round of refactoring code – tidying up classes, moving code that could be reused into more sensible places, and generally tidying up ready to launch my project on the world.
I checked out a new working version to use with my live database and was appalled at how slow the app had become. Loading the home page with around 100 tasks was taking a couple of seconds on my local machine; much slower than it had been before I refactored. I did some quick testing and saw that the delay was increasing with the number of projects and actions displayed.
First port of call, make sure the database indexes were set up right. All looked ok, apart from a couple of indexes that were now useful with the query chanegs I had made. Fixed these, but no dice.
Secondly, set up XDebug to pump out some profiling information, and use KCacheGrind to have a look. Not much I didn’t know, but confirmation that the time was all being taken in instantiating and displaying project and action objects. A brief look didn’t show anything up so I decided to leave it and come back to debug the paths through the app in Komodo when I had a bit more time. Very annoyed that my lovely, modular, readable, extendable code was behaving badly like this.
This morning I noticed that a page on our intranet was really taking along time to load, and saw a message in the status bar about bit.ly. Hmm. A quick trip to the Firefox add-ons window, and one uninstalled plugin later – all is fine. The page snaps up in super-quick time, and all is well. Lesson learned – test web apps in Firefox with all plugins turned off, and have confidence that the code I produce is good-quality code.