We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Obscure Go Optimisations - Bryan Boreham
Discover the lesser-known Go optimizations that can revolutionize your code's performance, from managing the garbage collector to implementing custom data structures.
- The Go garbage collector can be optimized by increasing the heap size, which can reduce garbage collection frequency.
- Pass slices instead of interfaces to reduce memory allocation and method calls.
-
The
len
,less
, andswap
methods can be implemented on a slice type without using interfaces. - Micro-optimizations can make a big difference in program performance.
- The Go garbage collector can be slowed down by increasing the soft memory limit.
- The garbage collector can be fooled into not running by allocating a large amount of memory upfront, known as “heap ballast”.
-
The
sort
function can be optimized by checking if the data is already sorted before calling it. - The Go runtime can be configured to use a larger heap by setting the soft memory limit.
- Avoid passing interfaces and instead use slices or pointers to achieve better performance.