In the simplest terms WordPress has no way to quickly sort and display large numbers of deeply nested pages, categories, and comments. It currently reconstructs the hierarchy from the MySQL tables each time the data is requested. For large sites this is simply unacceptable as it puts more strain on servers and takes longer to give the information back to the user than necessary.
Modified preorder tree traversal (referred to simply as MPTT from here on) is a tried and true method to quickly sorting hierarchical data in PHP/MySQL applications. Using MPTT, we can build a structure once which can simply be read off for each subsequent data request from the user. This means a single MySQL query for data and a simple while loop to actually print the results.
As pages, categories, and comments are added, removed, or moved about within the WordPress installation, the tree can be re-built quickly. In most cases, only part of the tree will need to be updated, as described in the “Adding a Node” section on this page.
For typical WordPress installations, there will be far more data requests from users than there will be data updates from authors, making this model very viable. Thus, for the average case, considerable performance gains should be achieved. This, of course, can be verified through some simple code profiling comparisons between the original and MPTT versions of WordPress with the same content.
Given the existing APIs within WordPress for inserting and particularly retrieving hierarchical data, the new MPTT code could be implemented with an identical (or at the very least, very similar) API such that most of the WordPress code which accesses this data could remain unchanged.
If this proposal needs more explanation, please just let me know and I’d be glad to provide more explanation on any particular aspect of the solution.
Schedule of Deliverables
* Generalized MPTT classes and methods
* Implementation for categories
* Initial profiling to insure viability
* Implementation for pages
* Implementation for comments
* Further profiling to determine overall success