As a web developer my main focus while working is performance. I want my apps to be blazing fast. I've always been obsessed with page speed, even way before announced that they would add page speed to their page ranking algorithm. This approach of mine seems contradictory with the fact that I prefrer php for web development. Without going through a bunch of technicalities, the way php runs (or used to run as we will soon see) is slower than other compiled languages (another technicality) like java.

So when I started coding Customization Engine (CE) Version 2 around two weeks ago I felt I had the responsibility of at least considering other development stacks. The first one I considered was NodeJs which is a program that makes javascript run in the server through Google's V8 engine. Google V8 Engine is what powers Google Chrome and is super fast. I loved NodeJs and actually started to code some parts of the app with it. Five days later I was feeling the pain. Not so much in learning a new language, because I use javascript a lot on the front-end, but more about developing with a new paradigm in mind. My impression (and this is very subjective) is that they way you work with NodeJs has a lot of potential of turning out like spaghetti code. It all has to do with the use of callbacks for almost everything and the use of the middleware design.

I wanted to check if there were any php alternatives with similar performance as NodeJs. Turned out there were. The first approach to speed up php is using Nginx + php5-fpm, instead of Apache and mod_php. I invested around five more days setting up a new Nginx+php5 stack and making sure everything worked more or less ok. This was a good point to upgrade the server machine, so I did that as well. Now CE runs on Nginx and php5-fpm and the performance boost is noticable in all my tests. Nginx is a great static files server, so images and other static files in CE are loading considerably faster. (No I'm not going to use cdn's for now. The customization templates are very dynamic and you change them a lot, cdn's would slow down your productivity).

Then I checked options to speed up php perse. I found two main alternatives: PhalconPhp and Facebook's HipHop Virtual Machine (hhvm). PhalconPhp is a web development framework that includes everything you'll find in any other frameworks like Laravel or Symfony. It has everything from Routing, ACL, MVS and even a really good ORM. The distinctive aspect of PhalconPhp is that instead of being php files (like Laravel or Symfony) it's actually a php extension written in C++. Translation: it's fast, very fast. Facebook developed hhvm to speed up their php code to serve their 1+Billion monthly users. It is a virtual machine or a program that runs on your server. It takes your php files and make them faster by translating them to a code that machines can understand and process faster. It'd be all good if you could use PhalconPhp and hhvm together, right? Well you can't. Hhvm runs on its own engine (I'm skipping lots of technicalities here), not on the regular php engine. PhalconPhp was made for the original php engine and the developers expressly said they are not planning on making it hhvm compatible.

The way I saw it: I could use PhalconPhp and most of the code would run faster than hhvm (again, skipping lots of technicalities), but things would slow down once I used regular php libraries. Or I could use hhvm and it would translate any php file into a code version very similar to PhalconPhp. Facebook is putting a lot of resources into improving hhvm, so that's a plus. Also, that meant I could reuse most of my current code and make it faster with hhvm instead of rewriting it with the PhalconPhp framework. So time is another plus for hhvm.

I had to invest around twelve days going back and forth many times and testing each of those options dozens of times. Now time is pressing and I need to get CE version 2 out soon so it can start serving stores out of Shopify. I already have some clients waiting to use it with BigCommerce and even in their own e-commerce platforms. Time being one of the most important factors I decided to use hhvm and continue developing the code I had already. The results are amazing! Hhvm makes my code run around 500% faster. Almost as fast as C++ code and definitely faster than NodeJs.

Now that my server and development stack is at par with Facebook (I'm using their stuff) it was time for me to get faster with CE version 2. And I did, see these screenshots: