Quick Guide: Go 1.23 Features

Emre Odabas
3 min readAug 14, 2024

--

Go 1.22 was released nearly six months ago, and the community has already released Go 1.23. If you wonder what comes with earlier versions, you could check For Quick Guide: Go 1.22 Features

This version mainly focused on range-over functions and some developer experiences. Let’s look at what comes with Go 1.23.

*https://appadvice.com/app/go-gopher/1458827152

Range over Functions

This feature was released in Go 1.22 as an experimental and it will be released on Go 1.23

You could use iterator functions on the range clause of for loops. Check for the details on this link. We could also define iterator functions as an alias in preview mode on Go 1.23

//iterator functions
func(func() bool)
func(func(K) bool)
func(func(K, V) bool)

type Seq[V any] = func(yield func(V) bool)

^^^ go top ^^^

Iterators

With Go 1.23, we could use the iter package that provides basic functions to work on slices and maps. Here is the list of those new functions.

//slices -> https://pkg.go.dev/slices@master
func All[Slice ~[]E, E any](s Slice) iter.Seq2[int, E]
func Values[Slice ~[]E, E any](s Slice) iter.Seq[E]
func Backward[Slice ~[]E, E any](s Slice) iter.Seq2[int, E]
func AppendSeq[Slice ~[]E, E any](s Slice, seq iter.Seq[E]) Slice
func Collect[E any](seq iter.Seq[E]) []E
func Sorted[E cmp.Ordered](seq iter.Seq[E]) []E
func SortedFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E
func SortedStableFunc[E any](seq iter.Seq[E], cmp func(E, E) int) []E
func Chunk[Slice ~[]E, E any](s Slice, n int) iter.Seq[Slice]
func Repeat[S ~[]E, E any](x S, count int) S
//maps -> https://pkg.go.dev/maps@master
func All[Map ~map[K]V, K comparable, V any](m Map) iter.Seq2[K, V]
func Keys[Map ~map[K]V, K comparable, V any](m Map) iter.Seq[K]
func Values[Map ~map[K]V, K comparable, V any](m Map) iter.Seq[V]
func Insert[Map ~map[K]V, K comparable, V any](m Map, seq iter.Seq2[K, V])
func Collect[K comparable, V any](seq iter.Seq2[K, V]) map[K]V

^^^ go top ^^^

Compiler Optimizations

There was an overhead when you built a larger project with profile-guided optimization(PGO). In Go 1.23, there will be a major improvement while building with PGO.

Also, the compiler will use information from PGO to align certain hot blocks in loops that will perform better up to %1–1,5.

^^^ go top ^^^

Timer & Ticker Updates

If you use time.Timer and time.Ticker on your program and deciding to upgrade to the Go 1.23 version, you should be aware of these two significant changes.

Firstly, Timers and Tickers will become loosely coupled with the program which means their objects could easily be removed by garbage collection.

As you know, the timer and ticker channels were buffered, sending the final signal even after closing them. This behavior will be changed in Go 1.23 and the channel will become unbuffered. So, if you use len and cap of timer channels then it will return 0 after this release. You should set

go 1.23.0

it on your go.mod file

In other words, if you want to ignore this behavior, you could use an older version of your go.mod file or just pass this variableasynctimerchan=1 to your Go environment.

^^^ go top ^^^

--

--

Emre Odabas
Emre Odabas

No responses yet