]> Cypherpunks.ru repositories - gostls13.git/commit
internal/godebug: define more efficient API
authorRuss Cox <rsc@golang.org>
Fri, 11 Nov 2022 17:36:31 +0000 (12:36 -0500)
committerGopher Robot <gobot@golang.org>
Mon, 14 Nov 2022 15:19:57 +0000 (15:19 +0000)
commitea4631cc0cf301c824bd665a7980c13289ab5c9d
tree78c1ee219438b55df5da49575bf4cbbefe590f1e
parent40bdcbb483548c0b660503c3ba80f9676b98fd5f
internal/godebug: define more efficient API

We have been expanding our use of GODEBUG for compatibility,
and the current implementation forces a tradeoff between
freshness and efficiency. It parses the environment variable
in full each time it is called, which is expensive. But if clients
cache the result, they won't respond to run-time GODEBUG
changes, as happened with x509sha1 (#56436).

This CL changes the GODEBUG API to provide efficient,
up-to-date results. Instead of a single Get function,
New returns a *godebug.Setting that itself has a Get method.
Clients can save the result of New, which is no more expensive
than errors.New, in a global variable, and then call that
variable's Get method to get the value. Get costs only two
atomic loads in the case where the variable hasn't changed
since the last call.

Unfortunately, these changes do require importing sync
from godebug, which will mean that sync itself will never
be able to use a GODEBUG setting. That doesn't seem like
such a hardship. If it was really necessary, the runtime could
pass a setting to package sync itself at startup, with the
caveat that that setting, like the ones used by runtime itself,
would not respond to run-time GODEBUG changes.

Change-Id: I99a3acfa24fb2a692610af26a5d14bbc62c966ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/449504
Run-TryBot: Russ Cox <rsc@golang.org>
Auto-Submit: Russ Cox <rsc@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
23 files changed:
src/cmd/go/go_test.go
src/cmd/go/internal/fsys/fsys.go
src/cmd/go/internal/modindex/read.go
src/crypto/x509/x509.go
src/go/build/build.go
src/go/build/deps_test.go
src/internal/cpu/cpu_test.go
src/internal/cpu/cpu_x86_test.go
src/internal/fuzz/fuzz.go
src/internal/godebug/export_test.go [deleted file]
src/internal/godebug/godebug.go
src/internal/godebug/godebug_test.go
src/internal/intern/intern.go
src/math/rand/rand.go
src/net/conf.go
src/net/http/server.go
src/net/http/transport.go
src/os/exec/exec.go
src/os/exec/lp_plan9.go
src/os/exec/lp_unix.go
src/os/exec/lp_windows.go
src/runtime/runtime.go
src/runtime/runtime1.go