time, runtime: use QueryPerformanceCounter in time.Now on Windows to improve time resolution #67066
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
OS-Windows
Performance
Milestone
Currently
time.Now
is using a low precision time, which makes a lot of duration measurements imprecise. Currently there seems to be onlyQueryPerformanceCounter
, which provides sub-microsecond precision for measurements. This lead to replacing time measurement workarounds in benchmarks (#31160).It's clear that using in benchmarking context QPC is fine, because that's what https://learn.microsoft.com/en-us/windows/win32/sysinfo/acquiring-high-resolution-time-stamps recommends. However it's less clear whether there are problems with measuring longer durations (e.g. several years) or whether there are peculiarities with call overhead.
To summarize, the open questions that would need answering before it's reasonable to change
time.Now
behavior are:time.Now
4.5ns.If this is implemented then the change in https://go-review.googlesource.com/c/go/+/557315 can be reverted.
Note, this would be only for the monotonic time measurements.
Related issue for benchmarking:
The text was updated successfully, but these errors were encountered: