We had several of these files, each about 10k in size, each imported into every main Genshi template.
This approach made it easy for Kyran to move us to Genshi but made for slower-than-desirable render times. Whilst speed-testing the pages I noted that the several 10k Genshi imports per page was the real burden.
The solution was to extract the necessary functions (div-blocks) from the helper files, put each of them into their own short Genshi file, and import only the necessary helper functions.
Now our main Genshi files need only import 3-10 helper functions (each file is about 10-30 lines long) rather than importing the several 10k files.
The speed-testing shows that each page’s imports took around 2 seconds per page before this process and 0.34 seconds after. The imports often dominated our render-times so this 6* speed-up is a welcome improvement.
For those who are new to optimisation we’re following the classical approach:
- Make measurements to identify the real bottleneck (very important!)
- Make changes one at a time to test their effect
- Keep the beneficial changes