I am sure being a developer at some point of time we all encounter performance issues with the code we are developing. The issues with the performance comes in to play once we have scaled the project considerably. And having said that there comes the biggest fear for the developer to explore the 1000s of line of code just pin point that small area that is causing the entire application to slowdown. The task is not a walk on rose petals but its also not as harsh as a marathon in Sahara.
Now, before we start optimization, we need to figure our which is the possible area of the application causing the issue. Is it the front-end, service side or database side. Without knowing the area we cannot fix the problem.
Hence, the first step would be to understand and figure out the area of your application that is causing the issue. For example if your page is slow because of the database query and if you optimize the front-end or server side code it is not going to improve the performance at all.
Here I am going to explain what are steps we can take for optimizations.
Front-end performance optimization
- All the JS, CSS and HTML in the project must be minified
- The images that you have used should be optimized for the web
- Check are we not binding extra event listeners? If we are binding multiple listeners on a single page it will slow down the page.
- Avoid fetching unnecessary data. Only fetch data that you want to show on the page. If you need only 10 rows don’t fetch 1000 rows and display only 10.
- You can try HTTP2 instead of HTTP1
- Light house is a tool from google will give you a detailed idea about what improvements needs to be done. That’s a good way to start.
- Webpack is really great tool if you are not using it. This is the time to start using webpack.
Database side optimization
- Don’t fetch extra data, if you want to display only 2 columns of a specific table than fetch only 2 columns instead of all.
- Inner join is better than left join as inner join do less row scan compare to left Join. So, if you don’t need left join than go with the inner join.
- Always create index for foreign keys.
- Avoid writing queries in the loop.
- Execute the ‘Explain’ plan of your query to get the idea what is wrong with the query. Is, your query really using index or not? How many rows are getting scanned. And do not forget to create proper index depending upon the query.
- Explain plan will give you a detail idea about is your query using temporary table or not. If your query is using temporary table then try to fix that problem.
- Create a proper index depending upon the where condition in the query.
Server side optimization
- Make sure you are not using unnecessary loops.
- Check the methods you are using that is not causing the slowness.
- Make sure the libraries you are using are not causing the issues.
- Check is your server running multiple processes or multiple threads in production mode.
- Perform load balancing if your server is not sufficient to handle the data.
- Process the time consuming tasks in the background. So, the user doesn’t have to wait for a long time on the front .
- Avoid pull mechanism for notification as it will create unnecessary load on server. Push mechanism is the better solution for the notification.
Caching Techniques for performance optimization
- You can use low level caching to cache your database queries with memcache store.
- You can use page caching when you are serving static pages.
- You can use HTTP caching if data is not changed server will respond with 304.
- We can use fragment caching for the hybrid application. As people are moving to SPA there is not much importance of fragment caching for those applications.
- You can use memcache database as a non persistent database. Memcache will delete data automatically if user is not requesting specific data regularly and maintain the data that user is requesting data regularly.
- You can also use redis database as a persistent database. Here your data will be maintained and will not be deleted at all.
Don’t process all your data upfront following are the cases where we should use background processing
- Email sending
- Export large PDF, CSV
- Import data on daily or weekly basis from third party
I am sure that if you follow the above mentioned tips, you have done the possible basic to intermediate level optimization of your application. The application should be performing perfectly paced for the basic usage.
Happy coding!· · · ·
Third Rock Techkno is a leading IT services company. We are a top-ranked web, voice and mobile app development company with over 10 years of experience. Client success forms the core of our value system.
We have expertise in the latest technologies including angular, react native, iOs, Android and more. Third Rock Techkno has developed smart, scalable and innovative solutions for clients across a host of industries.
Our team of dedicated developers combine their knowledge and skills to develop and deliver web and mobile apps that boost business and increase output for our clients.