The Go Windows port added support for high-resolution timers in Go 1.23, boosting resolution from ~15.6ms to ~0.5ms. This enhancement affects time.Tim

High-Resolution Timers on Windows

submited by
Style Pass
2024-10-02 06:00:02

The Go Windows port added support for high-resolution timers in Go 1.23, boosting resolution from ~15.6ms to ~0.5ms. This enhancement affects time.Timer, time.Ticker, and functions that put the goroutine to sleep, such as time.Sleep.

Using high resolution timers on Windows has been a long-standing request, tracked in golang/go#44343 and implemented by us (the Microsoft Go team) in CL 488675. It is important to note that Go used high-resolution timers on Windows before Go 1.16, but they were removed in CL 232298 because their implementation unfortunately conflicted with the Go scheduler, leading to latency issues. There wasn’t a good solution to this problem until recently.

Let’s explore how high-resolution timers made their way back to Go’s standard library and why it’s important.

A basic time.Sleep implementation (let’s call it the naive Sleep from now on) that uses the Win32 high-resolution timer API might look like this:

Leave a Comment