After the previous versions of Golang, we saw remarkable updates which helped to increase the efficiency of use. As Go promises to improve the compatibility. The new version promises this improvement.
In this blog, we will talk about the new features that make this language programmer-friendly. We will talk about the changes made in the language, tools, Go commands and many more things.
So let’s dive into this without wasting any time.
In this latest version of Go 1.21, we can see many updates that will help to make Go development experience better than before. The main changes are explained below:
min and max functions are introduced in Go 1.21. These functions will calculate the largest or smallest for the min value of a fixed number of given arguments.
This new function is responsible for deleting all the elements from a map or it will zero all the elements from a slice.
As compared to the previous version, the package initializing order needs to be specified more precisely. The new algorithm is as follows:
a. Find the first package in the list where all the imports are initialized already.
b. Remove the initialized package from the list.
Some programs may misbehave as they rely on a specific initialization order which was not expressed by explicit imports. As specs did not define the behaviour of these programs in the past releases.
All these other improvements are made to increase the power and precision of inference to improve the overall usability of Golang version 1.21.
In this version of the Golang Update, you will find that Go Toolchain has improved support for backward and forward compatibility.
The Backward Compatibility is made by making changes to control the default behaviour of GODEBUG. For example: In the earlier versions, if the programs were dependent on buggy behaviour, then fixing those bugs would result in the program break.
But after the improvements, we can observe some behavioural changes in Go. If we take the same example of bug dependency, we will see that Go can choose between old and new behaviour based on the Goline in the go.work file or in go.mod file.
It upgrades to the new Go toolChain but leaves the go line set to the older Go version. Hence, this version maintains the benefit of the older toolchain that supports compatibility as well as security.
Now, to improve the Forward Compatibility, Golang has made a strict requirement which is that you can not use Go. 1.21.0 with Go 1.20. This restriction would result in better results in error reporting as well as prevents unresolved import errors or syntax error.
All these restrictions will help to make this version manageable as Go can call a toolchain which is grouped with its own results and requirements. As a go.mod or go.work go line declares a minimum requirement on a newer version then this will run automatically.
The new changes revolve mainly around the -pgo build flag, -C dir flag. In Go 1.21, we will come across various updates.
-pgo build flag defaults into -pgo=auto, and now you can use this without specifying a single main package on the command line. If it finds a file named default.pgo in the main package’s directory. Then the go command will be used to enable the profile-guided optimization to build the corresponding program.
And some changes directly affect how we write the programs like:
In the previous updates, we have talked about PGO which was added as a preview. Now, in this latest version, it is ready for general use. It will help in adding additional optimizations on the codes which are identified as hot by the profile of the production workload.
The most remarkable feature of this version is the speed improvement. This is achieved by using the PGO at default for the binaries that improve the behaviour of the application by 2 to 7%.
These things have led to an increase in build speed up to 6%.
There are some changes in the use of frameless nosplit assembly functions when used on the amd64. Now this function will not mark NOFRAME automatically but it needs to be specified according to requirement.
Go 1.21 has tried to improve the interrogation of Go application with the Windows debuggers and other tools with the help of a linker which emits SEH unwinding data by default on Windows and amd64.
In this version, the compiler helps the linker to delete the dead global map variables, only if the number of entries in the variable intializer is big enough and when the initializer expression will not cause any side effect.
In this section, we will talk about the main changes made in the core library. We are going to talk about them in this section:
In this blog, we discussed the all teh major features which are made in the current version of Golang to help with increasing the compatibility of this language.
That’s all for now.
Hope you find this informative.