miekg/dns — pull request #80 by millerkil (2014-01-26 21:46:59+00:00)
Title: A couple optimizations

These optimizations target message packing in general. The first one saves string allocations by only allocating a new string when the buffer has changed. The second one caches the result of an "expensive" reflection call. [Type.Field](http://golang.org/src/pkg/reflect/type.go#L806) will allocate a bit of memory each call. There isn't anything particularly nasty about [Value.NumField](http://golang.org/pkg/reflect/#Value.NumField), but I found it saved another 300ns.
```
github.com/miekg/dns
---
BenchmarkMsgLenPack	5000000	8388 ns/op	1932 B/op	56 allocs/op

github.com/millerkil/dns # branch:optimize 1st commit
---
BenchmarkMsgLenPack	5000000	7010 ns/op	1157 B/op	39 allocs/op

github.com/millerkil/dns # branch:optimize 2nd commit
---
BenchmarkMsgLenPack	5000000	6395 ns/op	1117 B/op	34 allocs/op
```