The release of the Go programming language 1.22 has been announced, developed by Google with community involvement as a hybrid solution that combines the high performance of compiled languages with the advantages of scripting languages such as ease of writing code, fast development, and error protection. The project's code is distributed under the BSD license.
The syntax of Go is based on familiar elements from the C language with some borrowings from Oberon. The language is quite concise, yet the code is easy to read and understand. Go code compiles into standalone binary executable files that run natively, without the use of a virtual machine (profiling, debugging, and other runtime problem detection subsystems are integrated as runtime components), which allows achieving performance comparable to C programs.
The project is initially developed with an eye towards multithreaded programming and efficient operation on multicore systems, including providing operator-level tools for organizing parallel computations and interaction between concurrently executing methods. The language also provides built-in safety features against out-of-bounds access to allocated memory blocks and supports garbage collection.
Among the changes in the new release:
- The 'for' loops have been enhanced with support for defining ranges of integers; for example, to iterate over values from 0 to 9, you can now use the 'for i := range 10 {...}' loop.
- Experimental (GOEXPERIMENT=rangefunc) support for range functions has been added to 'for' loops, allowing the specification of a function as an iterator. For example, 'for i, x := range slices.Backward(s) {...}'
- A long-standing issue with 'for' loops that caused the sharing of loop variables across different iterations when calling goroutines has been resolved. For example, the code values := []string{"a", "b", "c"} for _, v := range values { go func() { fmt.Println(v) done <- true }() } will now output 'a', 'b', and 'c', instead of only 'c' as before.
- Memory management in the runtime has been optimized, resulting in a performance increase of 1-3% and a 1% reduction in memory usage in most applications.
- Work continues on implementing profile-guided optimizations (PGO) in the compiler that take into account features determined during program execution. The new version incorporates devirtualization techniques in the compiler to replace indirect calls to various methods with expanded inline blocks.
- With PGO enabled, the introduced change increased the performance of most programs by 2-14%.
- The compiler has added an experimental (GOEXPERIMENT=newinliner) improved implementation of the inlining mechanism, which uses heuristics to distinguish between important and secondary operations.
- The standard library has added the package "math/rand/v2," which offers a more comprehensive API and employs faster algorithms for generating pseudo-random numbers.
- The package net/http.ServeMux has been enhanced to specify methods and masks in patterns; for instance, the pattern "GET /static/{id}/" will be applied to requests with the HTTP method "GET" and will retain the value of the second segment of the requested path in the identifier "id."
- The package database/sql now supports the type Null[T], which allows scanning columns that can accept NULL values. Additionally, the slices package has introduced a Concat function to merge multiple slices of any type.
- The commands for working with workspaces (collections of modules) now allow the use of a vendor directory that contains dependencies for the workspace content. The directory is created when executing the command "go work vendor" and is used in build commands when the option "-mod=vendor" is specified (enabled by default if the vendor directory is present).
Changes in the behavior of utilities.
- The command go get is no longer supported outside of the module in the deprecated GOPATH mode (i.e., with GO111MODULE=off). Other build commands, such as go build and go test, will continue to operate for deprecated GOPATH programs for an indefinite period.
- The command go mod init no longer attempts to import module requirements from configuration files of other vendor tools (like Gopkg.lock).
- The 'go test -cover' command now prints summary coverage data for packages that do not have their own test files. Prior to Go 1.22, 'go test -cover' for such a package would report? mymod/mypack [no test files]
And now with Go 1.22, functions in the package are considered uncovered: mymod/mypack coverage: 0.0% of statements. Note: If a package contains no executable code at all, we cannot report a meaningful coverage percentage; for such packages, 'go test' will continue to report that there are no test files.
- The web interface of the trace tool has been slightly updated as part of the work to support the new tracer, resolving several issues and improving the readability of various pages. The web interface now supports exploring traces in a stream-oriented view. The trace viewer now also displays the total duration of all system calls. These improvements apply only to viewing traces created by programs built with Go 1.22 or newer. In a future release, some of these enhancements will be applied to traces created by older versions of Go.
- The runtime now stores garbage collection metadata based on types closer to each heap object. This change also reduces memory overhead for most Go programs by about 1% due to deduplication of redundant metadata. In some programs, the improvement may be less significant as this change adjusts the boundaries of the memory allocator's size class, so some objects may be moved to a higher size class. As a result, addresses of some objects that were previously always aligned to a 16-byte (or higher) boundary will now be aligned only to an 8-byte boundary. Some programs that utilize assembly instructions requiring memory addresses to be aligned to a size greater than 8 bytes and relied on the previous behavior of memory allocator alignment may fail, but we expect such programs to be rare. Such programs can be created with GOEXPERIMENT=noallocheaders, allowing a return to the old metadata model and restoring previous alignment behavior, but package owners should update their assembly code to avoid alignment assumptions, as this workaround will be removed in a future release.
- As mentioned in the Go 1.20 release notes, Go 1.22 now requires the final version of Go 1.20 or newer for initial builds. We expect Go 1.24 to require the final version of Go 1.22 or later for initial builds.
Original (go.dev)
Source: linux.org.ru
