martini-contrib / render

Martini middleware/handler for easily rendering serialized JSON, XML, and HTML template responses.
MIT License
245 stars 57 forks source link

Changed temporary buffers to a pooled bytes.Buffer implementation. #33

Closed elithrar closed 10 years ago

elithrar commented 10 years ago

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.

(I wrote a short article on this—scroll down to the last example for how I implemented it in my own application).

codegangsta commented 10 years ago

I love this! Thanks @elithrar!

codegangsta commented 10 years ago

I will pull this down and merge it

codegangsta commented 10 years ago

merged