top | item 9840066

(no title)

alanctgardner3 | 10 years ago

In my experience, almost all overhead in Go programs will result from being bitten by memmove, alloc and GC. Profiling any program that uses interface{} and byte buffers will quickly expose you to how much the runtime loves to reallocate and copy objects. In one instance I got 10x throughput improvement by switching from a generic interface (take an interface{} and detect the type) to using typed methods and hand-rolling a shim that called the appropriate methods.

discuss

order

ihsw|10 years ago

Do people actually use `interface{}` so liberally? I've never encountered it in the wild (except by newbies or as an example of what not to do) and I've always been under the impression that it's been heavily discouraged for a very long time.

midpeter444|10 years ago

interface{} is heavily used in many of the Go std libraries. Particularly for what I call "convenience methods" where you want to be able to pass in various types and it will do a type switch for you and then determine what to do.

Part of what I was discovering in this blog post is that if you look under the hood at these convenience methods, and you know in advance what type are passing (i.e., you are not using interface{}), you can often find the "direct" call to use that uses a concrete type and likely get better performance out of it.