After the big bang of Go 1.18, Go still continues to develop new features. If you miss what comes with 1.18, check my previous Quick Guide. For now, RC1 has already been released and the version will be released in August 2022. Let’s look at what comes with Go 1.19.
Atomic Types
Bool
, Int32
,Int64
, Uint32
, Uint64
, Uintptr
and Pointer
are new atomic types under sync/atomic
package. If you are unfamiliar, we could summarize the atomic package that
provides low-level atomic memory primitives useful for implementing synchronization algorithms*.
With these new types, we could use Load
,Store
, Swap
, CompareAndSwap
functions. TheAdd function is also could be used for numeric types. These functions simplify the code we have written before Go 1.19, and you can check this new code on Go Playground.
Soft Memory Limit
As you may know, when it comes to tuning memory on Go, you have only one option to set GOGC(runtime/debug.SetGCPercent)
. Even though this optimization basically gives a tradeoff between CPU and memory, it does not respect users’ memory limit**.
As described in the proposal, we could define a soft memory limit with the GOMEMLIMIT
environment variable or runtime/debug.SetMemoryLimitfunction
.
With this new feature, we could decrease memory limits and define better memory utilization. It could be time to leave behind the memory ballast workaround the twitch team gave us🙏.
New Functions
Go 1.19 has several changes in core libraries. When I checked those, I select some of them seems significant to me.
-
fmt
has new functions for appending data.Append
,Appendf
andAppendln
-
sort.Find
is a new function for finding the smallest index of i with given comparator function. It offers better experience thansort.Search
- Sorting algorithms switched to pattern-defeating quicksort for faster results for several scenarios.
- New
JoinPath
function (URL.JoinPath
method) creates a new URL by joining a list of path elements.
Unix build constraint
unix
is a new build constraint that is satisfied if GOOS
is one of
ios, linux, android, darwin, dragonfly, freebsd, hurd, illumos, netbsd, aix, openbsd or solaris
Compiler
The compiler now uses a jump table to implement large integer and string switch statements. Performance improvements for the switch statement vary but can be on the order of 20% faster. (GOARCH=amd64
and GOARCH=arm64
only)***.
You could check this benchmark for details.
With 1.19 version, the community works well and takes care of several performance optimizations. Many improvements and fixes will also be in this version. Those features are my selections. If I missed any fancy features, please contact me.
If you like to join our Gophers, you could apply for our open positions.
Top comments (0)