Quick review of Go 1.20 features
Profile guided optimization is used to generate more optimized code from using CPU profiles from captured running system.
- Add profiling to your program
defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
- Build your program as usual
- Run your program with under load
- Build your program with flag
-pgo <path/to/profile>
- Enjoy
You can run profiling of your code multiple times. Then you should merge your profiles go tool pprof -proto a.pprof b.pprof > merged.pprof
Now you can check coverage of integration tests of go programs. To try this just do following steps:
- Build program with coverage flag
go build -cover ...
- Run program with set env
GOCOVERDIR
- Optionally merge results
go tool covdata merge -i=<directories> -o merged
You can now convert arrays to
s := make([]byte, 2, 4)
a0 := [0]byte(s)
a1 := [1]byte(s[1:]) // a1[0] == s[1]
Errors now can wrap multiple errors
err1 := fmt.Errorf("first sample error")
err2 := fmt.Errorf("second sample error")
err3 := fmt.Errorf("third sample error")
complexErr1 := fmt.Errorf("first complex error %w, %w", err1, err2)
complexErr2 := fmt.Errorf("first complex error %w, %w", complexErr1, err3)