Quick Guide: Go 1.19 Features
Tags: go
Published: 2022-07-18 14:55:15

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](https://medium.com/@emreodabas_20110/quick-guide-go-1-18-features-e236d5b351ef). For now, [RC1](https://groups.google.com/g/golang-announce/c/Lu8ODY19HhA) has already been released and the version will be released in [August 2022](https://tip.golang.org/doc/go1.19). Let’s look at what comes with Go 1.19.
![Gopher 1.19](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7j744r8g12roh11zgqpc.png)

**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[*](https://pkg.go.dev/sync/atomic).

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](https://go.dev/play/p/4Trpfbd5jks) before Go 1.19, and you can check this new code on [Go Playground](https://go.dev/play/p/Iir_HEEMMLs?v=gotip).

![atomic-before-after](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t1i6zgbj1bqzz6ettqq8.png)

---

**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[**](https://github.com/golang/proposal/blob/150687b78c1d11cdb41572e75484c84280d5a963/design/48409/soft-memory-limit.src.md).

As described in the [proposal](https://github.com/golang/proposal/blob/150687b78c1d11cdb41572e75484c84280d5a963/design/48409/soft-memory-limit.src.md), 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 ](https://blog.twitch.tv/en/2019/04/10/go-memory-ballast-how-i-learnt-to-stop-worrying-and-love-the-heap/)workaround the twitch team gave us🙏.

---

**New Functions**

Go 1.19 has several changes in [core libraries](https://tip.golang.org/doc/go1.19). When I checked those, I select some of them seems significant to me.

- `fmt` has new functions for appending data. `Append`, `Appendf` and `Appendln`
- `sort.Find` is a [new function](https://pkg.go.dev/sort@master#Find) for finding the smallest index of i with given comparator function. It [offers](https://github.com/golang/go/issues/50340) better experience than `sort.Search`
- Sorting algorithms switched to [pattern-defeating quicksort](https://arxiv.org/pdf/2106.05123.pdf) for faster results for several scenarios.
- New `JoinPath` function (`URL.JoinPath` method) creates a new URL by joining a list of path elements.

![URL.JoinPath](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d92hfd02v7xh07jmtzd3.png)

---

**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](https://en.wikipedia.org/wiki/Branch_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)[***](https://tip.golang.org/doc/go1.19).

You could check this [benchmark](https://github.com/benhoyt/goawk/issues/121) 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](https://jobs.lever.co/trendyol?lever-via=q48u5LZ7k7).

![source: https://www.clipartkey.com/view/wJbmTT_gopher-dropping-the-microphone-gopher-go/
](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n60uqgp9bde86pbdotco.png)