Go 1.25 Features and Examples
Go 1.25 introduces profile-guided optimization, enhanced error handling, improved garbage collection, and experimental high-performance JSON support.

Go 1.25 introduces several significant language, compiler, and standard library improvements. Below is a comprehensive overview of the most notable features, with practical examples where possible.
Profile-Guided Optimization (PGO) Stabilized
Profile-guided optimization is now a stable feature. PGO allows the Go compiler to optimize binaries based on real-world execution profiles, leading to substantial performance gains (benchmarks show 2–7% improvements in real-world apps).
How to use PGO:
# Run your app with profiling enabled
go build -pgo=off myapp.go
./myapp -cpuprofile=profile.pprof
# Compile with PGO
go build -pgo=profile.pprof myapp.go
This process helps the compiler focus optimizations on the actual hot paths of your code.
Improved Garbage Collection
Go 1.25 brings enhancements to the garbage collector, reducing pause times and improving memory management, especially for large heaps. These improvements make GC pauses shorter and more predictable, which is crucial for latency-sensitive applications.
New Error Grouping and Formatting
- Error Grouping: Go 1.25 introduces a new way to handle multiple errors in concurrent code, making it easier to collect and process errors from goroutines.
Example:
package main
import (
"errors"
"fmt"
"sync"
)
func main() {
filenames := []string{"config.json", "data.csv", "settings.yaml"}
var errGroup errors.ErrorGroup
var wg sync.WaitGroup
for _, filename := range filenames {
wg.Add(1)
go func(filename string) {
defer wg.Done()
err := processFile(filename)
if err != nil {
errGroup.Add(err)
}
}(filename)
}
wg.Wait()
if err := errGroup.Err(); err != nil {
fmt.Println("Errors occurred during processing:")
errGroup.Range(func(err error) bool {
fmt.Printf("- %v\n", err)
return true
})
}
}
This pattern simplifies error handling in concurrent workflows.
- Improved Error Formatting: Errors now support more expressive formatting, including stack traces and error wrapping, making debugging easier.
Example:
package main
import (
"errors"
"fmt"
)
func main() {
err := deepFunction()
fmt.Printf("%+v\n", err) // Includes stack trace
fmt.Printf("%v\n", err) // Simplified view
}
func deepFunction() error {
return fmt.Errorf("level3: %w", middleFunction())
}
func middleFunction() error {
return fmt.Errorf("level2: %w", baseFunction())
}
func baseFunction() error {
return fmt.Errorf("level1: %w", errors.New("base error"))
}
New testing/synctest
Package
A new package, testing/synctest
, is introduced for testing concurrent code. It provides features like isolated "bubbles" for running tests and a fake clock for time-dependent testing. This makes it easier to write reliable tests for concurrent programs.
Experimental encoding/json/v2
Package
Go 1.25 includes an experimental, high-performance JSON implementation. Enable it with GOEXPERIMENT=jsonv2
at build time. The new encoding/json/v2
and encoding/json/jsontext
packages offer faster decoding and new configuration options for marshaling and unmarshaling.
How to enable:
GOEXPERIMENT=jsonv2 go build myapp.go
This opt-in package is expected to evolve, and developers are encouraged to test and provide feedback.
Language Spec Simplification: Removal of Core Types
The concept of "core types" has been removed from the Go specification. This change simplifies the language, making it easier to learn and use. Error messages are now more specific and no longer reference "core types," improving clarity for developers.
Compiler and Toolchain Improvements
- DWARF v5 Debug Info: The compiler and linker now generate debug information using DWARF v5, reducing binary size and speeding up linking, especially for large binaries.
- Prompt Nil Pointer Checks: The compiler now performs nil pointer checks promptly, ensuring programs that incorrectly use potentially nil values will panic as specified by the Go language spec.
Example of stricter nil check:
f, err := os.Open("nonExistentFile")
name := f.Name() // Now panics if err != nil
if err != nil {
return
}
println(name)
Previously, this would not always panic due to a compiler bug; Go 1.25 fixes this.
Summary Table
Feature | Description & Example |
---|---|
Profile-Guided Optimization | Use runtime profiles to optimize builds; 2–7% speedup. |
Improved Garbage Collection | Lower GC pause times, better memory management. |
Error Grouping & Formatting | Collect multiple errors from goroutines; improved formatting with stack traces. |
testing/synctest Package |
Tools for testing concurrent code with fake clocks and isolated test "bubbles". |
Experimental JSON v2 | Faster, configurable JSON encoding/decoding; opt-in via GOEXPERIMENT=jsonv2 . |
Language Spec Simplification | Removal of "core types" for easier learning and clearer error messages. |
DWARF v5 Debug Info | Smaller debug info, faster linking. |
Prompt Nil Pointer Checks | Stricter enforcement of nil pointer dereference. |
Go 1.25 delivers meaningful improvements for performance, error handling, testing, and language simplicity, making Go development more robust and efficient.