russross/meddler — pull request #4 by amattn (2013-08-24 04:58:31+00:00)
Title: Prepared Statment Cache

current benchmarks seeing approx 85% performance improvement with load, ~60% with save.

Most of what I learned about database/sql came from here:

https://github.com/VividCortex/go-database-sql-tutorial

A great read and one of the key takeaways was that you should pretty much always be using prepared statements.

This particular implementation of a statement cache includes lightweight wrappers around Exec, Query and QueryRows so that the cache can be a drop in replacement. Compare benchmark examples to see the two line code changes.

A more through implementation would possibly be integrated into Save/Load directly. Also a future enhancement could be the use of an LRU or adaptive replacement cache, rather than the naive, permanent cache in this pull request.