Permalink to this article – https://ift.tt/odK08rD
On May 7, 2022, US time, the development branch of Go 1.19 entered the new feature freeze phase, that is, only bugs could be fixed, and no new features could be added to Go 1.19. Since the previous version of Go 1.18 had major changes due to the introduction of generics, the release was delayed by a month, which directly led to the shortening of the development cycle of the Go 1.19 version.
Although the development cycle is nearly a month short, the Go 1.19 release is still scheduled to be released in August 2022. And the first beta version of Go 1.19 was released early this morning. What are the important changes in Go 1.19 version, I will give you a sneak peek through this article.
Note 1: The version feature changes are subject to the final release!
Note 2: This article is only a preview and will not go into too much detail. Details will be discussed after Go 1.19 is officially released.
generic problem fix
Although the Go core team has put a lot of effort into Go 1.18 generics, there are still known inherent limitations of generics after the release of Go 1.18, as well as some problems that have been gradually discovered, and Go 1.19 version will continue to polish Go generics , and focus on fixing generics issues found in Go 1.18. There are currently about 5-6 generics issues to be resolved in the development version of Go 1.19 . The possible release of some generic constraints mentioned earlier will not be fulfilled as expected in Go 1.19.
What is certain, however, is that Go 1.19 will include a fix to the Go syntax specification on generics , which is stated as follows:
The scope of an identifier denoting a type parameter of a function or declared by a method receiver is the function body and all parameter lists of the function. The scope of the identifier includes the function body and all formal parameter lists of the function.)
Changed to the following updated version:
The scope of an identifier denoting a type parameter of a function or declared by a method receiver starts after the function name and ends at the end of the function body. The scope of the identifier of the type parameter begins with the function name and ends at the end of the function body.)
Such a change makes the source code that compiles the error report under the current version of the Go compiler (Go 1.18.x) to compile normally in the Go 1.19 version:
type T[T any] struct {} func (T[T]) m() {} // error: T is not a generic type
Revised Go memory model
The Go memory model is the most abstract one in the Go documentation, no one! With the evolution of Go, the original Go memory model description is not formal enough in many places, and it also lacks the description of some synchronization mechanisms, such as atomic and so on.
This revision, referring to the description of the C++ memory model in “Foundations of the C++ Concurrency Memory Model, (PLDI 2008)” by Hans-J. Boehm and Sarita V. Adve, has made a more formal overall view of the Go memory model. Description, added descriptions of multiword races, runtime.SetFinalizer, more sync types, atomic operations, and compiler optimizations.
Revised go doc comment format
Go has built-in ability to extract comments directly as package documentation, unlike other languages that generate documentation through third-party tools. The go doc comment is a great convenience for Gopher. But the go doc comment was designed in 2009 and is somewhat outdated. There is insufficient support for many presentation forms or lack of more precise format descriptions. This time Russ Cox led the revision of go doc comment, adding format support for hyperlinks, lists, titles, standard library API references, etc. The revised go doc comment is not markdown syntax, but it borrows from markdown syntax and is compatible with the old comment format. Here’s a rendered rendering of some of the new doc comments provided by Russ Cox:
At the same time, the Go team also provides the go/doc/comment package, which can be used by gopher to easily parse go doc comments.
runtime.SetMemoryLimit
In Go 1.19, a new runtime.SetMemoryLimit function was introduced along with a GOMEMLIMIT environment variable. With this soft memory limit, the Go runtime will try to maintain this memory limit by limiting the size of the heap and returning memory to the underlying os more aggressively, so as to avoid the Go program from allocating too much heap and exceeding system memory resources. Killed due to restrictions.
The default memory limit is math.MaxInt64. Once the limit is set by SetMemoryLimit, the Go runtime will respect this memory limit, and by adjusting the GC recycling frequency and returning the memory to the os in time, the total size of the memory controlled by the Go runtime will be below the limit.
Note: The limit limits the total amount of memory controlled by the go runtime, and does not consider the memory that the developer applies for from the os (such as through mmap). For details of the specific measures of limit, please refer to the proposal design document .
Another thing to note is that this limit cannot 100% eliminate the out-of-memory situation.
Go 1.19 will raise the open file limit by default on startup
Upon investigation, some systems set an artificial soft limit on the number of open files, mainly for compatibility with code that uses select and its hardcoded maximum file descriptor (limited by the size of fd_set). Usually limited to 1024, some smaller, such as 256. This makes it easy for even simple programs like gofmt to run into an excess of open file descriptors as they traverse a file tree in parallel.
Go doesn’t use select, so it shouldn’t be affected by these limitations. So for go programs that import the os package, Go will increase these limits to hard limits by default in 1.19 .
Go 1.19 race detector will be upgraded to v3 thread sanitizer
Compared with the previous version, the race detection performance of the upgraded new version of the race detector will be improved by 1.5 times to 2 times, the memory overhead will be halved, and there is no upper limit on the number of goroutines.
Note: The working principle of thread sanitizer to detect data races: record the information of each memory access, and detect whether there is competition for the thread’s access to this memory. Based on this principle, we can also know that once race detect is turned on, the execution efficiency of the Go program will be greatly affected, and the running overhead will be greatly increased. Although the v3 thread sanitizer has been optimized, the overall impact on the program still exists and is still very large.
Go 1.19 adds “unix” build tag
Go 1.19 will add the “unix” build tag:
//go:build unix
Equivalent to
//go:build aix || linux || darwin || dragonfly || freebsd || openbsd || netbsd || solaris
Note, however, that “*_unix.go” retains the original semantics and is not recognized for backward compatibility with existing files, especially for use outside of the go standard library .
Some changes to the standard library
net package will use EDNS
In Go 1.19, the net package will use EDNS to increase the size of DNS packets to comply with modern DNS standards and implementations. This should help with some DNS server issues.
Add TextVar function to flag package
The Go flag package adds TextVar functions so that the flag package can be integrated with any Go type that implements encoding.Text{Marshaler,Unmarshaler}. for example:
flag.TextVar(&ipaddr, "ipaddr", net.IPv4(192, 168, 0, 1), "what server to connect to?") // 与net.IPv4类型flag.TextVar(&start, "start", time.Now(), "when should we start processing?") // 与time.Time类型
other
- On linux, Go officially supports the 64-bit Loongson cpu architecture (GOOS=linux, GOARCH=loong64).
- When the Go program is idle, when the Go GC enters a periodic GC cycle (once every 2 minutes), the Go runtime will now arrange fewer GC worker goroutines on the idle OS thread, reducing the number of idle Go applications. Occupation of os resources.
- The Go runtime will allocate the initial goroutine stack according to the goroutine’s historical average stack usage, avoiding up to 2 times the goroutine stack space waste for some goroutines.
- The sync/atomic package adds new advanced atomic types Bool, Int32, Int64, Uint32, Uint64, Uintptr and Pointer to improve the user experience.
- In Go 1.19, the Go compiler used jump table to reimplement the switch statement for large integers and string types, with an average performance improvement of about 20%.
summary
Go 1.19 is indeed a “minor release” relative to Go 1.18. However, Go 1.19’s update of memory model, the addition of SetMemoryLimit, the revision of go doc comments, and the continuous polishing of go runtime can still make gophers “little excited”, especially whether the addition of SetMemoryLimit can improve Go application factors. Let’s wait and see if the GC is not killed in time .
The milestone of Go 1.19 is here , and you can see all the features and fixes in this milestone.
“Gopher Tribe” Knowledge Planet aims to create a high-quality Go learning and advanced community! High-quality first published Go technical articles, “three-day” first published reading rights, analysis of the current situation of Go language development twice a year, read the fresh Gopher daily 1 hour in advance every day, online courses, technical columns, book content preview, must answer within six hours Guaranteed to meet all your needs about the Go language ecosystem! In 2022, the Gopher tribe will be fully revised, and will continue to share knowledge, skills and practices in the Go language and Go application fields, and add many forms of interaction. Everyone is welcome to join!
I love texting : Enterprise-level SMS platform customization development expert https://51smspush.com/. smspush : A customized SMS platform that can be deployed within the enterprise, with three-network coverage, not afraid of large concurrent access, and can be customized and expanded; the content of the SMS is determined by you, no longer bound, with rich interfaces, long SMS support, and optional signature. On April 8, 2020, China’s three major telecom operators jointly released the “5G Message White Paper”, and the 51 SMS platform will also be newly upgraded to the “51 Commercial Message Platform” to fully support 5G RCS messages.
The famous cloud hosting service provider DigitalOcean released the latest hosting plan. The entry-level Droplet configuration is upgraded to: 1 core CPU, 1G memory, 25G high-speed SSD, and the price is 5$/month. Friends who need to use DigitalOcean can open this link : https://ift.tt/1jTdnkV to open your DO host road.
Gopher Daily Archive Repository – https://ift.tt/E2Pvlna
my contact information:
- Weibo: https://ift.tt/e4hoDw6
- WeChat public account: iamtonybai
- Blog: tonybai.com
- github: https://ift.tt/MtiYOCW
- “Gopher Tribe” Planet of Knowledge: https://ift.tt/ZwN7D4L
Business cooperation methods: writing, publishing books, training, online courses, partnership entrepreneurship, consulting, advertising cooperation.
© 2022, bigwhite . All rights reserved.
This article is reprinted from https://tonybai.com/2022/06/12/go-1-19-foresight/
This site is for inclusion only, and the copyright belongs to the original author.