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 on this—scroll down to the last example for how I implemented it in my own application).
I've changed
bytes.NewBuffer
to a pooledbytes.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.
render.Options
if desired.(I wrote a short article on this—scroll down to the last example for how I implemented it in my own application).