From 6db9e3c0f98de1dd849bc6bbb28a652b896bf352 Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Thu, 20 Jan 2022 16:18:17 -0500 Subject: [PATCH 1/2] ddtrace/tracer/time.now(): Don't call .UTC() Unix time is defined as the duration since January 1, 1970 UTC. Calling .UTC() does unnecessary work to convert the "location" field of the time.Time object. The disassembly shows this new implementation is a few instructions shorter, but I doubt this will have any measurable performance impact. This is more about simplifying the existing code. --- ddtrace/tracer/time.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ddtrace/tracer/time.go b/ddtrace/tracer/time.go index b77f0745ef..86ac9d1253 100644 --- a/ddtrace/tracer/time.go +++ b/ddtrace/tracer/time.go @@ -3,13 +3,14 @@ // This product includes software developed at Datadog (https://www.datadoghq.com/). // Copyright 2016 Datadog, Inc. +//go:build !windows // +build !windows package tracer import "time" -// now returns current UTC time in nanos. +// now returns the current UNIX time in nanoseconds, as computed by Time.UnixNano(). func now() int64 { - return time.Now().UTC().UnixNano() + return time.Now().UnixNano() } From 8a51387e7c141e7c8911915576e4ebfd75eadd4c Mon Sep 17 00:00:00 2001 From: Evan Jones Date: Fri, 21 Jan 2022 10:51:13 -0500 Subject: [PATCH 2/2] time_windows.go: Make the same change to lowPrecisionNow --- ddtrace/tracer/time_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ddtrace/tracer/time_windows.go b/ddtrace/tracer/time_windows.go index 7775627bca..0eaa37e85d 100644 --- a/ddtrace/tracer/time_windows.go +++ b/ddtrace/tracer/time_windows.go @@ -23,7 +23,7 @@ func highPrecisionNow() int64 { } func lowPrecisionNow() int64 { - return time.Now().UTC().UnixNano() + return time.Now().UnixNano() } var now func() int64