Problem/Motivation
Book module's template function to load it's prev, next, up navigational structure is a pretty big performance hit (and rarely changes). When it does change, we know what the result of the book_prev, book_parent, and book_next functions will be. On any page once it's calculated once, we shouldn't need to do it again. Right now these are calculated every time, every page in a book, without the ability to cache this blob of data.
This was discovered as a result of a blog post I did on profiling drupal's footprint on page load -- https://drupal.psu.edu/blog/post/memory-profiling-hooks in which book_node_view was found to have a pretty large memory footprint.
Proposed resolution
Implement functionality currently residing on the book_cache module.
Remaining tasks
- Implement a cache_book cache bin similar to what is being accomplished via the book_cache module
- Test that this doesn't negatively impact rendering and all use-cases are being accounted for when it comes to times to expire this (or parts of this) cache bin.
User interface changes
None
API changes
None
Data model changes
Adds a cache bin for book module so that it can cache and expire this data correctly.
Patch forth coming.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | drupal-core-optimize-book-module-2538782-2.patch | 7.03 KB | btopro |
| #1 | drupal-core-optimize-book-module-2538782-1.patch | 6.9 KB | btopro |
Comments
Comment #1
btopro commentedproposed patch by backporting functionality from book_cache module
Comment #3
btopro commentedResolved notice that popped up from parent, cleaned up comment style slightly
Comment #4
cilefen commentedIs this an issue in D8 too?
Comment #5
btopro commentedtemplate_preprocess_book_navigation appears to be written the same way in D8... not sure the gains would be the same though (or nessecary) given that render_cache will cache what the output was going to be for this operation. It's effectively a render_cache of the details leading up to building this page. Would need some deeper profiling to see. In D7 the menu operations for this one function were like 500kb. This might still be the case in D8 but if its render cached (and always will be after initial build) I don't know what the point of tuning this function would be.
Comment #6
cilefen commentedI was wondering if something like that is the case—already handled in D8 by the advanced caching.
Comment #7
btopro commentedwould need someone else to step in and speak to that but that's my thinking at least. This is caching the associations of the menu table that are unique to books (who's next, previous, parent directly above me, tree below). While this could still be nice to have ahead of time, render cache would most likely expire in the event the node / surrounding menu items have changed... which would expire the cache_book... which would rebuild the cache_book and rebuild render_cache.
So at least in my understanding of it this wouldn't provide gains in D8 or excessively minimal at best.