Go 1 24
Overview
Go 1.24, released in February 2025, delivers substantial performance improvements and new security primitives. The Swiss Tables map implementation provides 2-3% overall CPU improvement, runtime.AddCleanup offers a better alternative to finalizers, and os.Root enables secure isolated filesystem operations.
Key Features
Swiss Tables Map Implementation
Faster map operations reducing overall CPU overhead by 2-3%:
// No code changes required!
// All maps automatically use Swiss Tables
users := make(map[string]User)
users["alice"] = User{Name: "Alice"}
// Benefits:
// - Faster lookups (15-25%)
// - Faster insertions/updates (10-15%)
// - Faster deletions (10-15%)
// - Overall program: 2-3% fasterruntime.AddCleanup
Modern cleanup mechanism replacing finalizers:
import "runtime"
type Resource struct {
id int
file *os.File
}
func NewResource(id int, filename string) (*Resource, error) {
file, err := os.Open(filename)
if err != nil {
return nil, err
}
r := &Resource{id: id, file: file}
// Attach cleanup function
runtime.AddCleanup(r, func(r *Resource) {
fmt.Printf("Cleaning up resource %d\n", r.id)
r.file.Close()
})
return r, nil
}os.Root for Isolated Filesystem Operations
Prevent path traversal attacks:
// Open root directory for isolated operations
root, err := os.OpenRoot("/var/app/data")
if err != nil {
log.Fatal(err)
}
defer root.Close()
// Open file (relative to root)
file, err := root.Open("config.json")
// Attempt path traversal
file, err = root.Open("../../etc/passwd")
// Error: Path escapes root directorySecure file server example:
type SafeFileServer struct {
root *os.Root
}
func (s *SafeFileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
file, err := s.root.Open(path.Clean(r.URL.Path))
if err != nil {
http.Error(w, "File not found", http.StatusNotFound)
return
}
defer file.Close()
info, _ := file.Stat()
http.ServeContent(w, r, info.Name(), info.ModTime(), file)
}Generic Type Aliases
Full support for parameterized type aliases:
// Generic type alias
type Pair[T any] = struct {
First T
Second T
}
p := Pair[int]{First: 1, Second: 2}
// Generic slice alias
type List[T any] = []T
numbers := List[int]{1, 2, 3}References
Last Updated: 2026-02-04 Go Version: 1.24+ (stable), 1.25.x (latest stable)
Last updated