Technology:
Memory usage is not the biggest problem when viewing a page on a Drupal Web sites, and code is not the biggest user of memory, but memory wasted by poor code organisation is memory wasted on every page view and soon adds up to a problem. When you create code, organise your code to avoid adding to the memory load.
This page talks mostly about Drupal 7. The approach can be used as far back as Drupal 4 because I used it back then. I promoted a reduction in memory usage for Drupal 6 and something similar to my approach was adopted. There is more you can do when you develop code or submit changes to exisitng code.
As an example, one small module was loading 10000 bytes of code for every page. I reduced the code load to 301 bytes for a normal page. An additional 9756 bytes is loaded for a very small number of specific pages.
How do you make the change?
In Drupal 4 and 5, you could split code into smaller files and include files only when needed but you had to specify the load yourself. typically You would have a small function loaded every page. The function would determine if other parts of the code are needed and perform an include using the PHP include feature. For a module, you would use a Drupal function to locate your own module directory then use your own code to load your additional module.
Drupal 6 added an option to specify code loads in menu settings, a system that automated the model I put forward. I developed and promoted several versions for different uses. The Drupal implementation was close to the first one I promoted and, like my demonstration cases, saved up to 80 percent in some modules.
Drupal 7 adds lazy loading of classes. You can use the lazy loading of classes as an easier way to automatically load your additional code.





- Facebook Like
- Log in or register to post comments