lib/pq — pull request #280 by bheatwole (2014-07-15 15:16:55+00:00)
Title: Cache time.Location for Better parseTs Performance

Previously a new time.FixedZone was created for every single timestamp fetched from the database. The time library treats the Location struct as immutable. It is also somewhat expensive to create as it uses two arrays internally in addition to the object itself. Since most applications will use relatively few time zones, caching is a good option to improve the performance here.

Prior Benchmark:
BenchmarkDecodeTimestamptz 1000000 1005 ns/op 213 B/op 5 allocs/op

Committed Benchmark:
BenchmarkDecodeTimestamptz 2000000 815 ns/op 66 B/op 2 allocs/op

Caching gives us slightly under a 20% speed improvement mostly coming from the reduction in allocations.