3 ms·
What were the general techniques you learned for optimizing Go?
by JulianMorrison 13y ago
What were the general techniques you learned for optimizing Go?
- dgacmu 13y agoGood question. I'm not sure I have a great mental list that differs from the "go community conventional wisdom" (whatever that is), but it was basically: - Avoid creating garbage unnecessarily, but don't go too crazy. It's often enough to, e.g., statically size those things you know are static. We tried adding a structure cache to our RPC/marshaler to further reduce GC, but it didn't prove helpful and just complicated our interface. - Pre-size data structures when you can (maps, arrays): Reduces performance variation as they dynamically resize. - Be careful of using introspection for things like marshaling. It's easy to create a bottleneck. - Batching is just - or more - important as it is in C++. - When you're doing complex stuff, be deliberate with how you prioritize request handling (). More on (): We found it incredibly important for the performance of our system to prioritize processing of existing requests over processing new request arrivals - up to a point. Making progress on an existing request helps reduce the number of goroutines/objects/etc. that're processing, so that everything runs faster. But you don't want to go too far or you starve for work. The key here was to think about it instead of letting your design happen to you. The most important is already known: Profile, don't guess. The profiling Go article is a good start.
- eternalban 13y agohttp://blog.golang.org/profiling-go-programs http://blog.golang.org/profiling-go-programs Profile first, always.