1.2.2

Latest release in branch 1.2
Released 11 years ago (May 05, 2014)

Software Go
Branch 1.2
Status
End of life
End of life December 11, 2014
First official release version 1.2
First official release date 12 years ago (November 28, 2013)
Release notes https://go.dev/doc/go1.2
Source code https://github.com/golang/go/tree/go1.2.2
Documentation https://go.dev/doc/
Go 1.2 Releases View full list

What Is New in Go 1.2

Go 1.2 introduces several key enhancements focused on the language specification, performance, and tooling. These changes refine the developer experience without breaking compatibility with Go 1.

Category Key Changes
Language Three-index slices, method value evaluation, cgo pointer rules
Performance Preemptive scheduler, heap size changes, stack size management
Tools Go test timeout, race detector on OS X, go doc improvements
Standard Library New encoding package, timeout for net.Dialer, crypto improvements

How did the language specification change in Go 1.2?

Three new language features were formally specified in Go 1.2. The three-index slice operation allows you to control the capacity of a new slice when slicing an existing array or slice. This provides explicit control over the new slice's underlying storage.

Method values now evaluate the receiver during the method expression evaluation, not when the resulting function is called. This matters because it fixes a subtle bug where a method value could use an unexpected receiver if the original variable was modified.

The cgo command now uses more precise rules for passing pointers between Go and C code. This prevents some cases of misuse that could lead to program crashes, making C interoperation more robust.

What performance improvements were made to the runtime?

The scheduler is now partially preemptive. In Go 1.1, a goroutine occupying a thread with a long-running loop could starve other goroutines on the same thread. The 1.2 scheduler introduces preemption points in function prologues to mitigate this.

Heap size management was tuned to be more aggressive. The garbage collector triggers a collection when the heap size doubles since the previous collection, rather than growing until it hits a fixed threshold. This often results in lower peak memory usage for many programs.

Stack size management also changed. The default stack size for new goroutines is now 2 KB, down from 8 KB. This allows you to create more concurrent goroutines without consuming as much memory, which is crucial for high-concurrency servers.

What new tools and flags were added for developers?

The go test command now has a default timeout. If a test binary runs for longer than 10 minutes, it is killed and the test is considered to have failed. This prevents broken tests from hanging indefinitely. You can override this with the -timeout flag.

The race detector, a killer feature for concurrency debugging, is now supported on OS X 64-bit systems in addition to Linux and Windows. This expands the environments where you can easily hunt down data races during development.

The go doc command was improved to show documentation for more entities, making it a more comprehensive tool for quickly checking API details from the command line without needing a browser.

Which standard library packages received significant updates?

New Encoding Package

The new encoding package provides shared interfaces implemented by other encoding packages like json and xml. This formalizes the contract for marshaling and unmarshaling data.

Net Package Timeouts

The net package's Dialer struct now supports a Timeout field. This allows you to set a deadline for establishing a connection, a fundamental requirement for building robust network clients that need to fail fast.

Crypto Enhancements

The crypto/tls package added support for the TLS 1.1 and 1.2 protocols. It also saw improvements to the cipher suite selection logic, enhancing the security of Go applications that handle encrypted connections.

FAQ

What is the practical use of the three-index slice syntax?
It lets you create a new slice with a specific capacity. For example, s := array[2:4:7] creates a slice with length 2, but a capacity of 5 (7-2). This is useful when you want to append to the new slice without affecting the original array's elements beyond the new slice's capacity.

Does the preemptive scheduler change how I write concurrent code?
Not really. You don't need to change your code. The change fixes a specific starvation scenario where a tight loop without function calls could block other goroutines. Your code will just work more fairly without any modifications.

Why was the default goroutine stack size reduced?
To reduce memory overhead. Creating a million goroutines with 8 KB stacks used 8 GB of memory just for stacks. With 2 KB stacks, that drops to 2 GB, making programs that rely on massive concurrency much more efficient and practical.

How do I handle a test that needs to run longer than 10 minutes?
Use the -timeout flag for go test. For instance, go test -timeout 30m sets the timeout to 30 minutes. This gives you control over long-running integration or stress tests.

Is the race detector on OS X as reliable as on Linux?
Yes, the implementation for OS X 64-bit is based on the same ThreadSanitizer library and provides the same level of detection for data races. This makes it a reliable tool for developers working on Apple hardware.

Releases In Branch 1.2

Version Release date
1.2.2 11 years ago
(May 05, 2014)
1.2.1 12 years ago
(March 03, 2014)
1.2 12 years ago
(November 28, 2013)
1.2rc5 12 years ago
(November 18, 2013)
1.2rc4 12 years ago
(November 13, 2013)
1.2rc3 12 years ago
(November 01, 2013)
1.2rc2 12 years ago
(October 18, 2013)