Performance discussions have been ramping up over the last few years. So much of an individuals life is spent online so companies are always trying to find ways to get things to the customer faster. Amazon.com has same day delivery in some areas, many internet companies are working on (or already have) gigabit connections for customers.
As developers, we should be doing our part. Our code should be efficient, bug free, etc. and there are several other tools and methodologies we have at our disposal to ensure this.
Code Reviews can help reduce bugs in code by having other developers look over your work. Misspell a variable name? Have the wrong scope? Double the load on the DB? Fellow developers can point these things out to you. Listen to their advice and don’t get upset. “Yes, it does double the database load, however, we account for that here with our additional caching layer, which is refreshed during non-peak times.” or “I didn’t know I should use let instead of var“. Value any feedback, good or bad, just don’t dwell on it.
Automated testing helps you not make the same mistake over again. No, not all code is testable, yes it takes time to write tests. There are many arguments against adding automated testing to a mature project, mainly time and budget. You don’t have to add tests to everything at once, you can do it one piece at a time. Just set up the test framework of your choice on your project. Write a test for the next bug you fix. Guess what, if your fix gets reverted (maybe a merge went sideways), you’ll catch it. Then, for your next code change/addition (your new code is testable, right?) write a test or two. Eventually you have a test sweet starting to take shape. The most tests you write, the more tests you want to write.
Caching is a hot topic with lots of opinions, methodologies, tools, frameworks, guru’s, etc. I’m not going to argue for or against anything here. I’m just going to highlight the benefits, and point out a downfall or two. If you are making repeated trips to the database for the same piece of data, cache it. If given a set of data, does your method always return the same for that set? If given a second set of data, does your method return the same that set? Cache the results. Once you have cached data your code doesn’t have to perform complex operations every time it’s run, you don’t have to make repeated trips the the database for the same value, etc. All this will help make your application faster.
In addition to pieces of code, you can cache full page renderings and serve up a cached version of the page instead of having to build it every time. This is very useful for pages that don’t change very often, or other files, such as CSS and JavaScript files.
Content Delivery Networks (CDNs) are servers that can serve up your images and other assets much faster than your webserver. Most CDNs share your content with other servers in different geographical locations. Your users will get the content from whichever server is closest to them, decreasing load times. Since a CDN takes care of serving you images, your webserver can focus on serving up your site.
AJAX is the term I’m going to use to refer to the next part. I want to stay away from any semantic arguments and/or framework fanboy interjection and just say there is value in this approach. Often referred to as a service based approach, your site can have static pages, be fully ADA compliant, fast, and heavily cached and still be dynamic. Using AJAX to communicate with your website’s back end for the dynamic pieces as it needs them and update the displayed content when it gets them your site can load “asynchronously,” meaning it will load more pieces at the same time. Typical sites are synchronous meaning that one piece has to load before another piece is loaded.
Conclusion
Using cached static pages, loading images from a CDN and loading dynamic content via fast API(s) that also uses caching will speed your site up tremendously.
I purposefully left this vague intending more as a quick intro/food for thought than a how-to guide. I can cover any other topics, so if you are interested, drop me a comment and I’ll see what I can do.