pencilblue/pencilblue — pull request #137 by brianhyder (2014-08-05 01:52:33+00:00)
Title: Template Engine Performance

Fixes #136
-----------------------

1 Core, templates cached in memory.
Numbers represent the number of milliseconds that it took for 99% of the requests to complete at or under
First Number is compiled, the second is the way we used to do it.

Admin Login:
1000 Total w/ 1 Concurrent: 28/31
1000 Total w/ 10 Concurrent: 47/173
100000 Total w/ 100 Concurrent: 681/2913

Home page:
1000 Total w/ 10 Concurrent: 373/1648

Under minimal load we see a performance boost of approximately 10%. As load increases we
see that more and more resources are consumed during the template processing stage and
things get a little backed up. In these circumstances we see performance gains of up to
427% by parsing the template once and creating an array of parts to be reassembled later.
For simple pages such as the admin login this makes sense. There are a minimal
number of replacements to be made which drastically reduces the number of template parts
that must be assembled. The home page is much more complex. Despite the complexity,
during concurrent load we still saw performance gains of approximately 440%.

The results of the performance improvements demonstrate that we were exhausting an
enormous amount of resources to iterate over each template. Taking the time to compile
the template and then cache it has proved to be much more efficient. The process is
completely backward compatible and only requires that any caches be flushed before
deployment.

The caveat is that not all forms of caching were tested. In addition, the case of caching
being disabled was not tested. In this particular use case I suspect we would still see
performance improvements due to the increased efficiencies of the parsing algorithm.