Magento 2 Performance Optimization: Steps to take for slow Magento Store – Part 1

Magento 2 Performance Optimization Steps to take for slow Magento Store_Part 1

Magento 2 is not a lightweight e-commerce platform.  It has been developed to serve thousands of buyers at an instant. But if your Magento store is not running fast then you may lose these customers within 3 seconds. Thus, it is essential that you optimize your e-commerce store for running it fast and getting more conversions.

Sites that run slow in this fast internet world end up losing the traffic and in e-commerce it negatively affect the conversions. A slower site also affects your ranking on the search engines. But you don’t need to worry a lot with Magento 2. You can take steps for optimizing its performance. But remember, a single fix would never be enough. This process involves a comprehensive approach.

Our Magento 2 developers are experts in Magento 2 speed optimization and they have gathered insights and actionable tips that work. In this article, we will go through all essential Magento 2 performance optimization fixes and suggestions to make your store run faster. By following these steps you will find significant improvement in the speed of your store. Let’s start with assessing your website performance:

a. Assess the Performance of your Magento 2 Store:

Before starting doing any fixes, you should first know the current performance of your store. In an e-commerce store, there are many website pages, but you should focus on the important pages of your store which are:

  • Homepage
  • Category pages
  • Product page
  • Cart
  • Checkout

Run performance tests before beginning the Magento 2 Speed Optimization:

There are many tools available to check the performance of your Magento store. You can go through the 10 Best Tools To Measure Your Magento Store Speed. We mostly use Google PageSpeed Insights for checking the store performance.

After getting the score, if it is less than 80 or has been marked as red or yellow then it is poor. Then check the Core Web Vitals assessment scores which are shown on the lower section of the page. Again, red or orange signify poor performance. Metrics such as First Input Delay and Largest Contentful Paint influence Google SEO. Thus, it is vital to improving these metrics for improving SEO rankings.

Check the Server Response Time:

Next, you have to check the time taken by the server to respond. TTFB (time to the first byte) tells you the time when the server sends your browser the first byte.  You should check it without the full-page cache. If the response time is more than a second it isn’t good. It shows that code is causing a large load on the server and each time the cache is flushed, users have to wait for a long time. Thus, if there are thousands of products in your store, the whole full-page cache will not have enough time to be generated. That’s why you have to optimize the site so it can work quickly without the full-page cache.

If you are checking TTFB with full-page cache, ideally aim below 100ms.

b. Make Required Upgrades

There is a huge possibility that upgrading your Magento to its latest version can improve its performance. So let’s take a closer look at what to boost.

Update your Magento store to the latest version:

This fix is required for both frontend and backend.

What is Problem?

Even if you are operating on Magento 2.0 then you should know that it is not the latest version of the platform. Magento keeps releasing its new version in almost 3 months. In each, there are significant upgrades, improvements in performances & security, and that’s why you can’t just stick to the older Magento version.

How it will help?

Upgrading your Magento store to its latest version will give you additional features, bugs and security fixes, and better performance.

How to upgrade your Magento store to the latest version?

At the time of writing this article (November 2021), the latest Magento version is Magento 2.4.3. Always remember, that upgrading your Magento store to the latest version can be trickier. For e.g. if there are multiple 3rd party extensions or themes on your store and if they don’t have support for the latest version, then upgradation can cause issues. An experienced Magento development company like us can help you with all aspects of Magento upgrade.

Make sure you are using a suitable hosting for your Magento store:

This fix is mostly required for the backend only.

Problem:

Magento requires a lot of resources. If you are currently using shared web hosting, then it can definitely slow down your store. The problems get worse when the traffic or load increases. Any shared hosting can manage a few users, but if the number grows to hundreds of users, its capacities are not enough. Server requests get piled in a queue so each user has to wait for the previous requests to be executed.

How it will help?

Using dedicated hosting or increasing the server capacity will optimize your store and it could serve more users simultaneously. Thus, requests wouldn’t need to wait in the queue and the site will perform faster.

How it is done?

Check the minimum hosting requirements for your Magento store and make sure your hosting can deliver that. If things are fine, you can decide whether you should change your Magento web hosting.

The decision will be based on the users you have on the site simultaneously and on the load it has. Analyze the resources a user needs and how much time the server spends on one user, and then how to distribute the resources.

Use HTTP/2 rather than using HTTP/1.x

It is a frontend fix.

What is the problem?

There is a significant number of static files in the Magento such as JS, CSS, media files, etc. In HTTP/1, a new server connection is created for every file. On the other side, HTTP/2 can process multiple static files parallelly at once.

How it is good?

The HTTP/2 can help your Magento store in the following ways:

  • Compress headers
  • Process multiple server requests at once
  • Work in parallel on a single connection

As a result, time isn’t being wasted in making connections. Thus, the website will serve responses faster.

Switch to HTTP/2

Currently, all the latest Magento hosting servers such as Apache 2.4.17+, Nginx 1.9.5+ etc. support HTTP/2 by default. The same is true for the CDN providers. You can use any chrome extension to know if HTTP/2 is enabled in the server settings.

Change PHP version:

It is a backend fix.

What is the problem?

Just like the Magento, the programming language also evolves and come in new versions. Thus, you should use the latest version of PHP which is PHP 7.

Use PHP 7.3 or 7.4 for now:

We recommend using PHP 7.3 or 7.4 which are stable and faster than the previous PHP 7.0 or PHP 7.1 versions. It is a fast code, decreasing the time to the first byte. Note: PHP 8 has already been released but we compare the performance of Magento with both PHP hhdsfdsfHP 8 and PHP 7 and find that results were better with PHP 7.3.

c. Check 3rd party extensions and possible Magento logic issues:

It is a backend fix.

What is the problem?

It majorly happens that to expand the functionality of the Magento store we use 3rd party extensions (free or paid). These extensions really help us by allowing us to offer better features on the site but at the same time they can also slow down the store. Other issues can also occur due to large data volumes or because your pages are jammed with too many elements, like widgets or sliders.

You must know that using a Magento performance extension is not a good idea and using more extensions will further degrade your store performance. It happens because each extension works independently, re-requesting data it needs (e.g., on a product), even if another extension has already requested it. In short, the more the number of extensions on your site, the lesser will be its performance. Why? Because the extension’s creators create universally applicable logic and are not especially curated for your store.

How it will help?

To resolve this issue, you have to investigate where your store stands today. Find out the essential features that you need to deliver your visitors and which extensions don’t serve any important purpose. After doing this, either remove the extensions or optimize them.

Review Page Performance with Magento Profiler:

How to approach profiling?

You can begin the Magento site performance optimization by determining what’s slowing the store down. On the basis of these findings, you can choose which modules, plugins, event observers, etc. you should optimize or remove. A profiler can give all such necessary information, There are a few possible paths with profilers.

A. Use Magento Profiler: Magento Profiler is an in-built tool that can inspect database queries and the calls of various methods. The profiler can find roadblocks, slow-downs and issues of performance. Also, it doesn’t need any other profiling extension and can use its own.

There are many different ways to enable the Magento Profiler. Our expert Magento developers will give you complete guidance.

B. Our Magento experts recommend specialized profiling extensions which can work a lot better than the in-built Magento profiler tool. These extensions can expand the profiling features and give better results. Here are two recommended tools:

o   Mirasvit Module Profiler: This is a very to use and add tool. It will give you a timeline showing which areas are not performing well and need attention.

o   MGT Developer Toolbar: It is a free add-on that works atop the Magento Profiler. It is quite similar to the Mirasvit Profiler and uses the same technology. But there is a difference in data representation, improvements in plugins, and inspection of events. You will get information about plugin lists, observer lists, etc.

C. If you want highly detailed profiling then you can also use PHP Xdebug Profiler. It can work outside of Magento at the PHP level, collecting data during the process of execution of PHP scripts.

After the profiling, you will have a list of problems that you have to tackle. Generally, the Magento performance optimization needs to narrow down to this scenario example.

There is a page that is taking a couple of seconds to load and the main cause behind this is 2-3 heavy elements and several plugins. One or more of these plugins might not be necessary at all and it is also possible that you have unused chunks of code. These problems need to be handled.

Removal of Plugins, Event Observers, etc.

Now since you have data about the problem areas in performance. You now know which plugin, file, module, class, event observer is causing the slowness. So either you have to optimize it or if you don’t need it, then remove it.

How to do it?

A.  Plugins Removal:

Removal of plugins is generally unlikely as the store owners only install those plugins which they need and they have paid for. Still, if there are old plugins that are of no use no, don’t hesitate to remove them.

It will help if you remove plugins that create numerous logs on all pages. These plugins initiate a load of unneeded tests and logs increases the page load time by 15%. To remove the plugins you can use SSH with certain commands to disable and delete the modules. You can also remove the plugins via Composer.

B.  Optimizing Plugins and Other Weak Spots:

The other case is optimizing plugins. Installing plugins in the Magento store has never been an issue. The main issue lies in their code.

Plugins vendors create plugins to sell it for many different solutions and that’s why they don’t give optimization much consideration. In many cases, the plugins are not even tested on a large data scope. So, it may occur that you will face the problem that the module’s logic for data load slows a store. It may be conspicuous in small data volumes but if hundreds if not thousands of visitors will browse your store, it will get slow down. Thus, if you don’t want to slow down the performance, you have to optimize it specifically for your store’s needs.

Common Problems Arise during the Magento Optimization Process:

While optimizing the Magento code, you can face various issues. It can be related to the performance of your plugins, event observers, modules, etc. Let’s know about them.

  • No caching on class methods levels: Suppose one of the website pages show something 20 times using the same data. Without caching, this page will be requested 20 times to get the same result. Duplicating calls to data requires a lot of time. Thus, instead of 20 requests, you can narrow it down to one variable that will return data in subsequent calls. It can be done using caching.
  • Executing unnecessary logic in the class constructor: There are some scenarios in which a certain code is not required every time within one specific method. Possibly, not during the page but later on (as a result of some AJAX request). However, other methods of this class may be required during the page load. At the same time, the constructor is always executed when a class instance is created. This leads to the call of unnecessary logic decreasing the performance. You can place the code from the constructor to the method, thus it will be executed only when required. If it will be executed all the time, it takes up valuable time.
  • Lack of caching for blocks that are present on all pages: Some page elements are displayed across the entire site, for e.g. the navigation menu with drop-down lists. Generally, the menu contains product categories. It is a heavy block with a complex structure and many elements. If there is no caching for such blocks, they will get loaded every time from scratch which will consume a lot of time.
  • Event observers in Magento: Magento 2 is distancing itself from observers and motivating developers to use plugins instead. But for now, both tools are present in the system. In Magento, event observers are attached to certain events and can dispatch them when required with the help of the event manager.

Wrapping Up:

In this Part 1, we have gone through points related to server optimization, Magento version upgrade, hosting, PHP version, and 3rd party extensions optimization for better performance. In the next release i.e. Part 2, we will go through Static Content optimization i.e CSS, JS and Image optimization, Database & search updates, improve caching, and how a Progressive Web App can make your Magento website faster. At Ceymox Technologies, the best Magento development company in India, we are having expertise in optimizing the performance of your store, increasing its security, version upgrade, and much more. We can develop a next-level e-commerce store in Magento with advanced features and functionalities. Let us know your requirements.

Leave a Reply

Your email address will not be published.

Captcha: 4 + 4 =

Have a project to discuss?

Let’s make something
amazing together

DROP US A LINE