What good is fast code if it is unmaintainable?
Depending on industry, time is relative. These optimizations will save you milliseconds on tight loops. In reality most apps aren't spending their time on tight loops. They are spending their time waiting for I/O or using inefficient algorithms. Neither of which these optimizations solve for.
If you are underperforming spec by 100ms it is likely you have one big change you need to make to save 100ms not 100 small micro-optimizations.
Only because most people don't have to do this there are still some people that have to do optimzation where possible.
I hope you understand that optimization without profiling is worthless. Once profiling is identifying something like your datastructure as some kind of bottleneck it might be worth a shot investigating that hint.
And these kind of articles are a nice summary of work being done, giving an overview over techniques and small tweaks that you might not have thought about previously.
It is good work by the author and he deserves being recognized for it. Not being dismissed by the bland statement don't waste your time with optimization.
Don't use defer when there is only one branch in your code.
Remove defer when optimising hot code paths.
Code will get changed over time and one code path often becomes two or more. Chances are, the next developer who adds code will not realize that the resource needs to be freed, or closed and simply forgets to add the defer. The only thing where defer really gets into your way is for error handling (because it can get verbose if you handle errors in defer).
In the grand scheme of things, defer is not noticeablily slower.
Use defer to make code readable. Go code should be readable, so you can figure out if it is correct, and only then should it be fast.
When benchmarking/profiling leads you to a hot spot in the code, rewrite it to remove defers.
This is typical: https://github.com/cornelk/go-benchmark/blob/master/defer_te...
Yeah, it's in the class of "things you should know about when optimizing tight loops", but not "things you should always be worrying about"; remember 5ns is on the order of a branch mispredict or an L2 cache miss [1]. If you haven't already squeezed out all the main memory accesses you can from your algorithm at 100ns a pop, or if you're in code dealing with networks (routinely micro seconds, even within datacenters; milli seconds if you have to leave), or files, or anything else like that, micro-optimizing defers is not going to have any visible results to your speed but can very badly damage your code's correctness and ease of writing and modifying.
The other thing to know about defers is that they are not declarations, they are instructions; every time the program counter moves past one, another defer call is added to the stack of calls to make while exiting the function. So you do have to be careful about deferring in a loop, not so much because it's "dangerous" but just because it's easy to be unaware that the defers are not declarations. If you intend to do it, it's fine, it can just bite you if you do it accidentally.