Shopify/liquid — pull request #189 by boourns (2013-05-13 06:50:08+00:00)
Title: Cache tokenized partial templates

@burke @camilo @hornairs /cc @tobi

A very common pattern in liquid templates is to do
```
for i in product
include snippet, with i
endfor
```
Currently `include` loads and tokenizes the template on every iteration of the for loop.

Since templates are immutable, we can store a copy in the context and re-use it whenever the same snippet is `include`d. *This speeds up benchmarking the New Standard theme by ~9%*.

Also adds 'include' support for the benchmark suite, which gave the results below:

Benchmarking against `Standard` Shopify theme before:
```
Rehearsal ------------------------------------------------
parse: 5.860000 0.050000 5.910000 ( 5.919422)
parse & run: 14.430000 0.170000 14.600000 ( 14.586308)
-------------------------------------- total: 20.510000sec

user system total real
parse: 5.850000 0.030000 5.880000 ( 5.889104)
parse & run: 14.340000 0.150000 14.490000 ( 14.489024)
```

After:
```
Rehearsal ------------------------------------------------
parse: 5.920000 0.060000 5.980000 ( 5.986115)
parse & run: 12.510000 0.100000 12.610000 ( 12.607375)
-------------------------------------- total: 18.590000sec

user system total real
parse: 5.830000 0.010000 5.840000 ( 5.842107)
parse & run: 12.440000 0.100000 12.540000 ( 12.533233)
```

This came to me as I fell asleep after 14 hours of travelling.