PrestaShop/PrestaShop — pull request #2317 by studiokiwik (2014-12-08 10:41:14+00:00)
Title: translations - level 2 cache performance patch

This is a performance patch for Prestashop 1.6.x (although it should work also for 1.5.x)

Idea is quite simple: to cache translated strings depending on the current context. Every context (defined loosely as language / shop / theme / controller / frontend vs backend combination) uses only small subset of translations. Instead of loading every time all translations availables, we are using only those which applies to current context. If a translation is not
in the cache, we are launching a full procedure (including and parsing translation files, calculating keys etc) . Once all actions for given context are executed, cache is saturated and there is
no longer need to use base system (apart of modyfing new translations; in such case cache is purged and regenerates anew during subsequent calls)

Additionally, level 2 cache is in json format, which is parsed faster than php.

Performance analysis:
We observed gain of about 4-5% (~20ms from 400 - 500ms on our test infrastructure) when cache is saturated. There is 20% less files included (148 vs 187 on homepage). Potential gains can be even bigger when there is more traductions or I/O system is less performant (separated or netoworking file servers etc.).
When cache is cold, which occurs only one or few times depending on complexity of context, performance loss is negligeable ( 1 file read, 1 file write and possibly 1 mkdir, less than 2 ms for the script with 100% miss ratio on homepage)

There is certainly room for improvement (better context segmentation, include mail translations, use this possibilty for make cleanup of translation system etc ), but I hope that's a good start yet.