martini-contrib/render — pull request #33 by elithrar (2014-06-12 12:31:10+00:00)
Title: Changed temporary buffers to a pooled bytes.Buffer implementation.

I've changed `bytes.NewBuffer` to a pooled `bytes.Buffer` implementation.

This reduces garbage per-request and increases performance. Some local testing (across both Martini and a non-Martini application) saw a ~26% improvement in req/s (26k -> 33k) when making this change, and less allocations when profiled (reducing the calls to makeSlice). I've also tested a fixed (10K) buffer which sat in-between, but was less flexible as it heavily depends on the typical response size of the application.

- Pooled buffers reduce garbage per-request (render)
- Set default size as 64 as testing shows minimal memory impact and good
performance (no noticeable gains above 64 buffers) - this could be exposed in `render.Options` if desired.
- Buffer returned to pool after writing rendered template to
ResponseWriter.

(I wrote [a short article](http://elithrar.github.io/article/approximating-html-template-inheritance/) on this—scroll down to the last example for how I implemented it in my own application).