Magento Performance Optimisation

Nobody likes a slow website, especially Google, so we’ve put together a guide on how to squeeze the most out of your website in an easy to follow guide. We’ll cover some really simple changes you can make to your store, along with some more technical aspects.

As always, if you have any questions or want to discuss a project, feel free to contact us on 01423 740152, or alternatively via email at

Right, let’s get stuck in!

Magento Configuration

Ok, so first things first, let’s make sure you’ve got Magento configured in the best way to get some additional speed.

  • Enable Magento Caches – Magento caches give an enormous performance boost to your website for free, so they should be enabled all the time. It is also recommended to have all caches enabled on your development and staging environments in order to detect possible caching issues before pushing them to production. To do this, go to System > Cache Managementcache-management
    The level of performance boost given by the cache can depend on the use of third-party extensions – a Magento block is not implicitly cached and needs to have the necessary caching properties implemented to instruct the cache on how (or whether) to remember the output of a block. AoE_TemplateHints is a very useful module for auditing your block cache-ability. Once installed (on development only, this should never be used on a production site), you can enable template hints on any page by appending to the URL the parameter ?ath=1. This provides hover-over information popups on your page blocks with information about the caching of that block. If this reveals an uncached block which may involve a large amount of processing (e.g. loading products or other expensive DB reads), you should consider adding caching to the block by overriding the necessary methods in the block class:getCacheKeyInfo()

    The cache key info allows you to create different versions of that block based on any set of parameters, e.g. whether the user is logged in, their customer group, or the current store ID. The lifetime method will be used to determine when a cache entry is no longer valid, and the block should be completely reprocessed and stored again to use from that point onwards.

  • Turn off PHP Compilation – The reason for this is that PHP has developed several mechanics to improve applications containing lots of files. As a result PHP compilation usually impacts performance negatively, so it should stay off. OPcache is often the preferred solution for optimising the execution of PHP files. This removes the need for loading and parsing PHP scripts on each request by storing pre-compiled script bytecode in memory.
  • Turn on the Magento Flat Catalogs -Magento uses the Entity Attribute Value model to store customer, category and product data. This makes them incredibly extensible, but it results in longer SQL queries and more database reads. Enabling the Flat Catalog for Categories and Products merges all data into two tables (one for products and one for categories), thereby improving performance. This is mostly useful for sites with large product catalogs, but it could be enabled for websites with small catalogs too.To do this, go to System > Configuration > Catalog and under the Frontend section, turn on the Flat Catalog options.flat-catalog
    When enabling the product flat table for the first time, take some care to review typical user stories through the site. Custom blocks which rely on custom product attributes may fail if the custom attribute doesn’t exist on the flat table but is being requested. If this situation does come up, consider refactoring the code to load the attribute value using the built-in attribute resource models, or add the attribute to the flat table by setting the “Use in Product Listing” value to ‘Yes’ in the attribute editor of your admin dashboard. It’s always recommended to turn this on at the beginning of a project to avoid any unwanted issues.
  • Disable unneeded Magento modules, logs and reports – Magento comes with several features enabled that are not needed for most websites, so it is recommended to disable the ones you are not planning to use. For instance, the compare and the recently viewed products features are very resource expensive so it is highly recommended to disable them if you are not planning to use them. The same applies to all reports and some logs like the visitor log. You should disable modules direct via the XML files which are located in /yourstore/app/etc/modules/module_name.xml

    Logs can usually be disabled via the admin panel, by going to the module via System > Configuration and disabling the log options.
  • Ensure Magento indexes are set up correctly – Indexes can be set to either run manually or automatically. Running them automatically helps ensuring that all indexes are up to date, although it comes with a performance cost, so you might consider setting them to run manually especially if you are planning to run an import process or something similar.
  • Uninstall any unneeded extensions – This is particularly important for third party extensions, because it is very tempting to just leave them there after installing them even if they are not being used anymore, but this could hurt performance a lot.

Your Server

  • Go with a reputable host – One of the main issues we come across when carrying out performance audits for clients is that their server is severely underpowered for what they require. Invest in a good host who knows what they are doing and spend some money getting the hardware recommended to you. We’d recommend our friends over at Sonassi Hosting for Dedicated servers. They’re extremely quick and a very knowledgable bunch on Magento!
  • Ensure you’re using MySQL 5.6 or above – MySQL 5.6 comes with great performance and scalability improvements. That’s why it’s important to use at least version 5.6 on your website.
  • Ensure you’re using PHP 5.6 or above – PHP 5.6 offers several advantages compared to its previous versions, such as better performance and more efficient memory usage.
  • Check your core_url_rewrites table – The core_url_rewrites table stores all the URL rewrites defined by Magento for product and category pages. However, it can grow large very quickly, so it is recommended to keep an eye on this table, especially when running the Catalog URL rewrites index very often. If you’re having an issue with numbers being appended to the end of your URLs in Magento, then check out this fix here.
  • Minimise any form of redirects – It’s very important to avoid long redirect chains, since this could have a negative impact on the overall performance of the website.
  • Enable Expire Headers – This feature allows you to cache your website files for a specific amount of time in your customers’ browsers, so it should be set up accordingly in order to minimise the number of times the same file has to be sent to the same customer. Inchoo have written a great guide on setting this up here.
  • Enable GZip Compression – The apache mod_deflate module is used for compressing text, css and javascript files before being sent to the browser.
  • Disable and remove any unused Apache modules – It is very important to have a clear understanding of which Apache modules are actually being used. This would simplify the creation of other server environments for the website, and it will allow us to remove the unused ones, which could give us a performance boost.
  • Set up a multi-server environment – For increased capactiy, you could have your website running in multiple web servers through a load balancer, all connected to the same database server. There are many options for this which Digital Ocean have covered well.
  • Disable / Rotate Customer Logs – The logs can grow exponentially large if left unattended, so it is highly recommended to set up a solution for rotating logs or to disable them. Yireo have written a great little extension for disabling logs which can be found here.
  • Set up Query Caching – Database servers spend a lot of processing time into parsing queries. This time can be greatly reduced by setting query caching correctly. Crucial have written a guide on setting this up here.
  • Fix any performance bottlenecks – We regularly have clients approach us who because of performance bottlenecks on their website. Newrelic is an excellent application for providing bottleneck visibility, but it can cause performance costs. Sonassi have put together an article here about the best way to implement it with their MageStack OS.
  • Install a Full Page Cache solution -There are several Full Page Cache solutions available, in the form of Magento extensions (such as LestiFPC, Mirasvit FPC, Enterprise Edition FPC and so on) or complete solutions (such as Varnish). However, this cannot make the dynamic sections of your website faster, so it shouldn’t be the first focus for optimisation. See Sonassi’s notes on Cache management for more advice.

Image Optimisation

  • Use CSS Image Sprites – A website with many images can take a really long time to load. A solution for this is to put all the images into a single Image Sprite. There are some fantastic tools online for creating Sprites easily. Alternatively, you can look at solutions like SASS when building your theme.
  • Optimise your Images – A quick and easy way to reduce load time on your website is to optimise your images and reduce file size. A fantastic tool for Mac is ImageOptim and Riot for Windows. You should also make sure that images are the correct size and that you’re not loading images which are much larger than what is displayed to the user.
  • Load your assets on a Subdomain – This allows the browser to transfer all the static content in parallel. Most browsers currently can only load 6 assets at a time, which means that if you have lots of images, JS and CSS files being loaded on a page, the browser will stall until a file has fully completed. Alternatively, use a CDN (be careful to make sure it’s as quick/quicker than your current server!).

Good Practices For Writing Optimal Magento Modules

  • Take advantage of Magento caching – If you are writing a piece of code that takes a long time to compute try caching its result using any of the cache types defined in Magento.
    Use Magento entities for retrieving information from the database, but consider using raw SQL for the most resource expensive operations.
  • Use pagination when working with large product collections – All collections in Magento can be paginated which means that you can minimise the amount of data retrieved from the database and the number of objects built for a particular operation or process.
  • Minimise the number of database accesses – This sounds like an obvious one, but it is important to store intermediate results in order to avoid loading them again. This is particularly important when working with Magento entities, since loading them from the database and hydrating the objects consume a lot of memory and processing.

Good Resources for Testing Site Speed

  • Pingdom – A great tool for getting a quick overview of what assets are slowing down the site load time. It’s worth mentioning that results should be taken with a pinch of salt as server render time cannot be accurately tested via Pingdom. Visit Pingdom here.
  • GTMetrix – A really strong tool for running tests on individual pages of your site. Similar to Pingdom, it shows you load time, along with Google PageSpeed and YSlow results so you can see what assets are slowing down your website along with an overview for improvement. Visit GTMetrix here.

Ultimately, it’s always recommended for you to implement a solid plan of action so that you can measure every change before and after it has been implemented. There is no quick fix for site speed improvements and what improves performance on one store can degrade performance on another.

N.B: Special thanks to Sonassi for their input on the above article.

Last Updated: 23-02-2016.