SeriesPart 1 of 9 // Go 1.24
GoWriting
Feb 7, 2025
5 min read

Introduction to Go 1.24: What’s New and Why It Matters

Go 1.24 is set to be released in February 2025, bringing with it a host of improvements in performance, tooling, language features…

Go 1.24 is set to be released in February 2025, bringing with it a host of improvements in performance, tooling, language features…

Introduction to Go 1.24: What’s New and Why It Matters

Go 1.24 is set to be released in February 2025, bringing with it a host of improvements in performance, tooling, language features, cryptography, and runtime enhancements. This blog post serves as an introduction to the key updates, providing an overview before diving into specific changes in future posts.

Why Upgrade to Go 1.24?

With Go 1.24, developers can expect:

  • Performance improvements: Swiss table-based maps and optimized runtime internals lead to faster execution.
  • Better tooling: JSON support for go build and go test, new dependency tracking with tool directives, and enhancements to go vet.
  • Security upgrades: New cryptographic packages (crypto/mlkem, crypto/hkdf, crypto/pbkdf2, crypto/sha3) and FIPS 140-3 compliance.
  • Language enhancements: Full support for generic type aliases, reducing redundancy in complex codebases.
  • Testing enhancements: The new testing.B.Loop function simplifies benchmark iteration, and the testing/synctest package helps test concurrent programs more effectively.
  • Filesystem security improvements: The os.Root type enables directory-limited filesystem access, enhancing security in containerized and sandboxed environments.

1. Language Enhancements

Generic Type Aliases

Go 1.24 now fully supports generic type aliases, allowing type aliases to be parameterized, similar to defined types. This improves code reusability and simplifies generic programming.

Example: Generic Type Aliases

type List[T any] = []T

Previously, generics required explicit definitions, but now type aliases can be used directly, making code more maintainable.

2. Performance Improvements

Go 1.24 introduces Swiss Tables for map operations, leading to significant performance gains. With this, we should see measurable improvements, especially for large datasets.

Faster Compilation and Optimized Code Generation

  • Better register allocation: Reduces redundant memory accesses.
  • Faster function inlining: Reduces function call overhead.
  • More efficient stack frame layout: Improves function calls and memory usage.

Measuring Compilation Time Improvements

3. Security and Cryptography Updates

Go 1.24 strengthens security with:

  • New **crypto/mlkem** package: Implements post-quantum cryptography standards (ML-KEM-768 and ML-KEM-1024).
  • New hashing and key derivation functions: crypto/hkdf, crypto/pbkdf2, crypto/sha3.
  • FIPS 140–3 compliance: New GOFIPS140 environment variable ensures cryptographic compliance.

4. Testing Improvements

New testing.B.Loop for Benchmarks

The traditional b.N loop can be error-prone due to several reasons:

  • Incorrect Use of **b.N** in Setup Code: Expensive setup operations inside for i := 0; i < b.N; i++ can skew benchmark results.
  • Loop Iterations Not Scaling Well: Large b.N values may distort results.
  • Optimization by the Go Compiler: The compiler may optimize away computations inside b.N loops.
  • Inconsistent Iteration Control: b.N dynamically increases, which can affect consistency.

Why b.Loop() is Better

According to Go issue #61515, b.Loop() provides:

  • Automatic iteration control
  • Proper setup and clean-up handling
  • More predictable benchmarking

Example:

func BenchmarkMyFunction(b *testing.B) {
  for b.Loop() {
    MyFunction()
  }
}

testing/synctest for Concurrent Testing

The synctest.Run function enables better testing of concurrent code:

package main
 
import (
  "testing"
  "testing/synctest"
)
 
func TestConcurrent(t *testing.T) {
  synctest.Run(t, func() {
    go someConcurrentFunction()
    synctest.Wait()
  })
}

5. Tooling Enhancements

JSON Support for go build and go test

The -json flag now provides structured output, making it easier to integrate with CI/CD pipelines and debugging tools.

go build -json ./...
 
go test -json ./...

New tool Directives for Dependency Management

Go modules can now track executable dependencies directly using tool directives in go.mod, eliminating the need for tools.go files.

go get -tool golang.org/x/tools/cmd/stringer

Alternatively, tools can be directly added to go.mod:

tool golang.org/x/tools/cmd/stringer

6. Garbage Collection Enhancements

Go 1.24 improves garbage collection (GC) performance by lowering GC overhead, optimizing large object handling, and ensuring more predictable latency. These optimizations result in better memory management, reducing the impact of GC pauses in high-performance applications.

Final Thoughts

Go 1.24 is a major step forward, providing performance boosts, security hardening, and developer-friendly enhancements. Over the course of this series, we’ll explore these features in-depth, providing code examples, performance benchmarks, and migration tips.

Stay tuned for the next post, where we dive deep into Go 1.24’s generic type aliases and how they simplify code maintenance.

By Ajitem Sahasrabuddhe on February 7, 2025.

Series contents