The Magento 2 Performance Guide

- E-Commerce, Magento 2


Good performance is a key aspect of a successful ecommerce project. It is not only important as a vital ranking factor, but is highly appreciated by customers. Thus, a fast online store often has a higher conversion rate than a slower one. As a result, it turns more visitors into buyers and helps to increase sales. Now, when the importance of Magento 2 performance is obvious, it’s time to shed light on how to increase it in case of the platform.

We already have a detailed guide to Magento 1.X productivity, but the second version of the platform differs a lot and requires another approach to performance improvements. Magento 2 is faster, less resource-hungry, and better optimized for high loads than 1.X. Besides, it offers a lot of new performance features out-of-the-box. For instance, you get native support for Varnish, Redis, and Nginx as well as full page caching in Magento 2. As for the first version of the ecommerce platform, all these features were only available through customizations and extensions.

Although Magento 2 provides better opportunities related to performance, there is still a lot of work to be done before your ecommerce store will be as fast as the platform allows. The easiest way to achieve better Magento 2 performance is related to modules. We recommend you to install the following solutions to speed up your Magento 2 website:

Note that the platform always gets lots of important performance improvements, so we recommend you to update your store to the latest stable Magento 2 version.  It’s also a good idea to check whether your modules and theme support the latest version you are going to update to.

As for a more complex way, let’s start with a presentation by Max Pronko. In the following slideshow, Max answers whether performance in Magento 2 is the same as or slower than Magento 1. He also discusses nuances related to sample data and Vanilla platform comparison. Furthermore, Max shares optimization techniques that will dramatically improve the default productivity parameters of Magento 2. So if you are looking for effective Magento 2 performance improvements, follow the advace by Max Pronko.

Full Nginx Support

how to use nginx with magento 2

Another Magento 2 performance optimization is related to Nginx that has been developed with three core principles in mind: high performance, high concurrency, and low usage of memory. Thus, it significantly increases the speed of every website. To handle requests, Nginx utilizes an event-driven asynchronous approach, while the default Magento 1.X is based on a process-oriented approach with the Event MPM as the asynchronous processing model. Due to event-driven architecture, Nginx shows more predictable performance even under higher loads.

As mentioned above, Magento 2 offers a native support for this solution, so it can be easily installed on top of the platform. To find out how to perform this procedure, check this Magento 2 Nginx Configuration guide. Besides, Magento 2 has a recommended Nginx configuration in the root folder. You can also check it on GitHub here.

Magento 2 and Redis

using redis with magento 2

Redis also introduces a field for Magento 2 performance enhancement. It is an advanced key-value cache which provides top notch performance and offers such features as value incrementation in a hash; pushing an element to a list; appending to a string; getting a sorted set of members with the highest ranking; and set intersection, union and difference computing.

It incorporates several use cases for in-memory datasets, which are the reason of high performance results. Thus, you can either persist it by dumping the dataset to disk or append each command to a log. Moreover, if you need a feature-rich, in-memory cache, the persistence can be disabled.

Besides, Redis incorporates non-blocking synchronization and auto-reconnection with resynchronization partial on net split. All these features make it a lightning fast solution for every ecommerce website, especially for a Magento store.

If you don’t know how to install and use Redis with the second version of the popular ecommerce platform, check this Magento 2 guide: Magento 2 Redis Configuration.

Different Cache Types

How to Manage Magento 2 Cache

You don’t need to install any Magento 2 cache extension, since the platform works with the following types of cache:

  • Configuration cache appears when Magento gathers configuration from modules. It also includes store-specific settings from database and the file system.
  • Layout cache includes compiled page layouts .
  • Block HTML output cache consists of HTML page fragments per each block..
  • Collections data cache gathers database queries.
  • DDL cache is designed to work with database schema.
  • Entity attribute value cache includes Metadata related to EAV attributes: store labels, attribute rendering, search settings, etc.
  • Page cache gathers data about generated HTML pages.
  • Translations cache is related to merged translations from modules.
  • Integration configuration cache is aimed at compiled integrations.
  • Integration API configuration cache consists of compiled integration APIs.
  • Web services configuration cache is the cache of a web API structure.

Magento 2 Cache Types

You can find appropriate configurations under System -> Cache Management. For further information, check our Magento 2 Cache Management guide.

Full Page Cache (FPC)

Full Page Cache in Magento 2

Full page caching is so powerful due to the ability to store the full page output in a cache. As a result, subsequent page loads do not require much server load. Thus, full page caching is mandatory for high-traffic websites, as it keep server load as low as possible and helps to avoid downtime even when traffic is really high. In addition, by using full page caching, you will get significant Magento 2 speed optimization, since all the server needs will be reduced to fetching and rendering pages from the cache.

And if FPC was absent in Magento 1 by default, the new version of the platform includes it, but you still need a warmer, to keep your cache version always up to date (see extensions mentioned in the beginning of this post). If necessary, Magento can clean up this cache automatically, but you can still put any data in any segment of the cache manually. please note that it is necessary to clean or flush FPC after modifying any code level that affects HTML output. Always keep this cache enabled, since it significantly improves the performance of Magento 2.

Varnish Cache

Magento 2 Varnish Guide

Varnish cache is an HTTP accelerator for heavily consumed APIs and content-heavy dynamic websites. Magento 2 supports this cache out of the box, so you can easily configure it for your ecommerce project to increase the default performance.

Every web server receives HTTP requests, but does not return HTTP responses immediately. Therefore, a long sequence of steps required for each request. Multiplied by thousands of requests, these steps lead to server overloads, heavy resource consumption, and a significant performance decrease. Unfortunately, the server does not remember even repeated requests, but you can fix this problem with the aid of Varnish. It receives requests instead of your web server, looks at what’s being requested, and sends requests to your web server, which sends a response to Varnish to pass it back to the client. It seems that such procedure only slows down the server, but the performance increase occurs when Varnish begins to store responses from the back end in its cache. As a result, it can rapidly serve further repeated responses without any need to connect to the back-end server. Besides, Varnish uses in-memory cache storage which makes it even faster.

As for Magento 2, this cache can be easily configured according to the requirements of the platform under STORES > Configuration > ADVANCED > System > Full Page Cache. For further information, check our How to Configure Varnish for Magento 2 tutorial.

Varnish cache in Magento 2

CSS Preprocessing

CSS Preprocessing in Magento 2

Although CSS has a very powerful syntax, it can easily grow to enormous sizes when working on non-trivial projects. Luckily, we can easily fix this problem with the help of CSS preprocessors: SASS and LESS. Both allow additional leverage over CSS by offering enhanced syntax, but for the Magento 2 development we will focus on  LESS. It’s core features are:

  • Nested syntax;
  • Ability to define variables and mixins;
  • Operational and mathematical functions;
  • Multiple files joining.

If you are not familiar with this CSS preprocessor, pay attention to the following documentation:

CSS and JS minification

CSS and JS minification in Magento 2

In Magento 2, CSS and JS minification procedures are almost the same as in case of 1.X. By combining, compressing, and caching Javascript and CSS files, you can improve the performance of your Magento 2 website. Thus, it’s only a matter of time when appropriate tools will be available. Besides, you can perform everything manually:

Magento 2 CSS and JS minification

Catalog images caching

Catalog images caching in Magento 2

Magento pre-generate cropped product images in different sizes to reduce processing on every page load. Thumbnails are generated during the first image load and can be easily removed.

Code Generation

Code Generation in Magento 2 2

Code generation provides you with the ability to bring aspect oriented programming, generic programming, and other complicated techniques to languages, which do not support them by default. As a result, you can improve Magento 2 performance and add unique features to the default setup. There are two ways to trigger code generation in Magento 2. First of all, you can perform it on the fly:

  • Use a meaningful name that follows a certain pattern to declare a class.
  • Now, the system should autoload the class. If it can not find it, the class will be generated.

Unfortunately, this approach slows down the system, so we recommend you to utilize the command line. By using the following command, you will force the system to inspect the code and generate all necessary classes.

This approach speeds up the system, so it is useful for production.

With the aid of both approaches, you will get generated classes in MAGENTO_ROOT/var/generation directory.

For further information check this article: Introduction to code generation in Magento 2.

RequireJS for Improved JS Performance

How to use RequireJS within Magento 2

There is the official documentation related to the configuration of JavaScript resources, but are going to focus our attention on RequireJS. Being a JavaScript modular script loader, this tool is optimized for both JS environments and in-browser use; therefore, it suits best for Magento 2.  RequireJS is used to improve the quality of code and the speed of apps. Since JavaScript does not provide any ways for specifying code required to execute a file, RequireJS plays a crucial role in the improvement of JS development: it specifies dependencies between JS files and load them into a browser. Such an improvement leads to a significant jump in Magento 2 performance, therefore we recommend you to check this article: Advanced Development with RequireJS + Magento 2 Tutorial.

Session Storage Management

Session Storage Management in Magento 2

Another useful performance improvement is related to session storage management. You can move it from files to the database or Redis.  Use the –session-save option with any of the following:

  • db will move it to the database. It is necessary to choose database storage in case of a clustered database.
  • redis will move it the Redis backend.
  • files should be used to store session data in the file system.

We strongly recommend you to store everything in Redis, since Magento 2 fully supports it and you can prevent your store from performance degradation. In case of a large number of users both your database and file system suffer a dramatic decrease in productivity. As a result, your Magento 2 website slows down leading to a terrible user experience. Thus, Redis is the only reliable option.

Out-Of-The-Box CDN Support

CDN in Magento 2

Since Magento 2 also provides support for CDN support, media and static content can be loaded from separate subdomains located on different servers of CDN networks. CDN options can be configured under Stores -> Configuration -> Web. Thus, you get another Magento 2 performance improvement out of the box.

CDN settings in Magento 2

At the same tine the second version of our Control for CloudFlare extension allows you to control the CloudFlare system directly from your Magento 2 admin. It offers better integration as well as more flexible connections between Magento 2 and CloudFlare than its first version (and the default Magento 2 solution). Check the manual for more information.


Besides tons of new features and improvements introduced in PHP 7, we will get a language with completely new performance. It will be much faster than the latest available 5.X, and Magento 2 will fully support it. Thus, PHP 7 will change our understanding of how fast an ecommerce shop could be. For a deeper insight into PHP 7, check this post: PHP 7 – features, release date, rumors; and don’t forget to examine a current problem related to PHP 7 and Magento 2: String class name issue for php7.

PHP 7 in Magento 2

Magento 2 vs Magento 1 Performance

You can compare the performance of both platforms via MageMeter – an amazing service from Inchoo. From the below picture, we can see that the latest Magento 2 beta with disabled caches already beats Magento 1 Enterprise Edition:

Why Magento 2 is better than Magento 1

Magento 2 Extensions

We’ve already reviewed lots of useful Magento 2 extensions. As for Magento 2 performance modules, we recommend you to explore Magento 2 Catalog Search Engines and Magento 2 Full Page Warmers. These are the most efficient solutions that increase the performance of Magento 2. Choose one that suits your needs from each category, and you will significantly increase Magento 2 speed.

General Server Side Improvements

Although the new version of Magento offers tons of improvements compared to 1.X, there are still a lot of common performance optimizations. You can find all of them in our Magento Performance Ultimate Guide. Check the links below to find the appropriate tutorials”

  • OPcache is a code caching module designed to improve that part of your Magento 2 performance which is related to PHP. It uses a shared memory for storing precompiled script bytecode. Thus, OPcache eliminates the PHP’s need for loading and parsing scripts on every request. Therefore, by optimising OPcache settings, you can dramatically improve the performance of your Magento 2 website. Follow this link – OPcache – for further optimizations.
  • MySQL and alternatives. Proper configured MySQL is among the most important enhancements to the performance of Magento 2. First of all, it requires the understanding of your hardware; then, you should know what settings to use. But MySQL is not a necessity, since these are two reliable substitutes: MariaDB and Percona. Follow this link – – MySQL – for further information.
  • New Relic. A slow page is always a good reason to leave a webstore and never return again. Luckily, there are a tons of different monitoring tools developed for identifying the problem timely; and one of them is New Relic. Follow this link – – New Relic – for further information.

Magento Performance: Know Your Database

In this presentation, Ivan Chepurnyi describes how to set up a MySQL database. He offers 4 effective tricks, which will help you increase the performance of your Magento website significantly.

Useful Presentations

Oleh Kobchenko explains how to configure Magento 2 to get maximum performance

Ivan Chepurnyi shows how to get maximum performance with proper Magento 2 Layout and Code Compilation:


This was our short guide to Magento 2 performance. We are going to update is as soon as new information will be available. For more tips related to Magento 2 development, check our Cookbook. For other important information, visit this page: Everything about Magento 2 on Firebear.

Do you have any thoughts about Magento 2 performance? Don’t hesitate to share them via comments below.