Go 1.22 has already been released, learn about its new features and improvements


Go is a concurrent, compiled programming language with static typing inspired by C syntax.

The new version of Go 1.22, arrives six months after version 1.21, with a number of notable changes to the toolset, runtime, optimization improvements, compiler improvements and libraries.

For those who don't know about Go, I must tell you that this isIt's a programming language being developed by Google with the participation of the community as a hybrid solution that combines the high performance of compiled languages ​​with advantages such as scripting languages ​​such as ease of writing code, speed of development and protection against errors.

Go 1.22 main news

In this new version, which is introduced from Go 1.22, highlights two changes in the "for" loops, Ya que Previously, variables declared by a for loop were created once and were updated in each iteration. In Go 1.22, each iteration of the loop creates new variables to avoid accidental sharing errors, in addition Added experimental support (GOEXPERIMENT=rangefunc) for range functions to for loops, which allows you to specify a function as an iterator and resolved a long-standing issue with for loops which caused coroutine calls to share loop variables between iterations. Additionally, for loops can now loop through integers. For example:

package main import "fmt" func main() { for i := range 10 { fmt.Println(10 - i) } fmt.Println("go1.22 takes off!") }

Another notable change in this new version is the introduction of the ability to use a directory «vendor« which contains the workspace dependencies. Now the commands you can use this directory, which is created with `go work vendor` and is used in build commands when ` is set-mod` in «vendor«, this being the default value when a directory exists «vendor» in the workspace.

It is important to note that the functionality of `go get` is no longer supported outside of a module in mode GOPATH inherited However, other build commands like `go build` and `go test` They will continue to work indefinitely for legacy GOPATH programs. Furthermore, the command `go mod init` will no longer try to import module requirements from configuration files of other «“vendoring” (like Gopkg.lock).

Go 1.22 introduces a new package io/unsafe which provides functionality to work with pointers and unsafe memory. This package provides methods for converting pointers to and from safe and unsafe types, as well as for performing memory copy operations without bounds checking.

Work continued to include optimizations in the compiler based on the results of the pPGO code profiling, and is that now the compiler uses devirtualization tools to replace indirect calls of various methods with expanded inline block execution. When PGO was enabled, the added change improved the performance of most programs by 2% to 14%.

In the version of Go for Windows, programs that link or load libraries Go built with -buildmode=c-archive o -buildmode=c-shared can now use the Event Logging Windows (ETW) API through the new packages runtime/trace y tracehook, which implement the Go event trace collection protocol as an ETW provider.

Of the other changes that stand out:

  • The command go test -cover now prints coverage summaries for covered packages that do not have their own test files.
  • os/exec, the ability to define context attributes has been added, allowing you to set values ​​such as the working directory, environment variables, and input/output file descriptor for executed commands.
  • Optimized memory management in runtime, resulting in a 1-3% performance increase and a 1% reduction in memory consumption for most applications.
  • The package net/http, the function has been added CloseIdleConnections to the HTTP client, which closes all idle connections that the client has recently used
  • An improved experimental implementation (GOEXPERIMENT=newinliner) of the call insertion mechanism has been added to the compiler, which uses heuristics to separate important operations from non-important ones.
  • Package has been added » math/rand/v2 » to the standard library, which offers a more consistent API and uses faster algorithms to generate pseudorandom numbers.
  • The package net/http.ServeMux Added the ability to specify methods and masks in templates.

Finally, if you are interested in knowing more about it, you can check the details In the following link.

Leave a Comment

Your email address will not be published. Required fields are marked with *



  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.