Estimated Time To Read This: 2 – 4 minutes
If you’re like me, I’m sure you’ve said this at one time or another during the software development process. The app that just takes forever to load – and then gives you that nasty fatal error message. With some fiddling and a bit of adjusting, you usually get this to work, but it’s still slow. What do you do?
Following from my last blog, I’ve started using phpStorm for my developing here at CoreSolutions. Part of this suite includes an extensive set of tools to help debug your apps. With the addition of the xDebug extension, a plethora of new, usually hidden information is now available to both you and your favourite tools – in this case kcachegrind.
Kcachegrind is a profiling tool for PHP that allows you to visually look through all the processes you have to run in order to display a page. Available for Windows, Linux and Mac, installation is an app that is quite easy to use. Kcachegrind is divided into a few main panels. On the left (and shown below) is the list of all the functions used within the page load, sorted by inclusion cost:

In this particular page (the main index page of PD Place), you can see that the Preferences object plays a significant role in the loading of the page. While taking 7 ms itself to load the load_preferences_to_session method (3rd line), 54% of the page load is involved with processes underneath this call. How can you find out more? Look at the panels to the right:
This graph shows a call graph of methods used to call the method above, as well, it shows you in percentage, what’s taking the time are part of that method. In this case, the ADODB calls are the ultimate culprit. The right branch of the tree tells us that these methods are called 520 times in the course of this methods execution. If any optimizations are to be done, optimizing in these methods would produce far greater results than the Execute methods listed in the left branch.
Tweaks and performance enhancements can easily be measured by profiling your changes as you optimize and speed up your app. If you’re curious, try profiling your favourite WordPress installation and see what the results are – you may be surprised by the results.
Mark






