From 5dcaf9a01b5e91074c7750823e94e08e1829cc36 Mon Sep 17 00:00:00 2001 From: thepudds Date: Sat, 25 Oct 2025 00:49:45 -0400 Subject: [PATCH] runtime: add GOEXPERIMENT=runtimefree This CL is part of a series of CLs to triangulate between the runtime, compiler, and standard library to reduce how much work the GC must do. An overall design document is in CL 700255. This CL stack implements a runtime.free within the runtime, and then uses it via automatic calls inserted by the compiler when the compiler proves it is safe to do so. In the future, we can also consider possibly a limited set of explicit calls from certain low-level portions of the standard library. When called, runtime.free allows immediate reuse of memory without waiting for a GC cycle. The goals include less overall CPU usage by the GC, longer times between GC cycles (with less overall time with the write barrier enabled), and more cache-friendly allocations for user code. Here, we just add the GOEXPERIMENT=runtimefree flag. It currently defaults to on, but can be disabled with GOEXPERIMENT=noruntimefree. The actual implementation starts in CL 673695. Updates #74299 Change-Id: I2f1f04dbdca51f4aaa735fd65bb2719c298d922e Reviewed-on: https://go-review.googlesource.com/c/go/+/700235 Reviewed-by: David Chase Reviewed-by: Michael Knyszek LUCI-TryBot-Result: Go LUCI --- src/internal/buildcfg/exp.go | 1 + src/internal/goexperiment/exp_runtimefree_off.go | 8 ++++++++ src/internal/goexperiment/exp_runtimefree_on.go | 8 ++++++++ src/internal/goexperiment/flags.go | 3 +++ 4 files changed, 20 insertions(+) create mode 100644 src/internal/goexperiment/exp_runtimefree_off.go create mode 100644 src/internal/goexperiment/exp_runtimefree_on.go diff --git a/src/internal/buildcfg/exp.go b/src/internal/buildcfg/exp.go index f1a1d8632ef..31195f94c08 100644 --- a/src/internal/buildcfg/exp.go +++ b/src/internal/buildcfg/exp.go @@ -83,6 +83,7 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (*ExperimentFlags, error) { RegabiArgs: regabiSupported, Dwarf5: dwarf5Supported, RandomizedHeapBase64: true, + RuntimeFree: true, SizeSpecializedMalloc: true, GreenTeaGC: true, } diff --git a/src/internal/goexperiment/exp_runtimefree_off.go b/src/internal/goexperiment/exp_runtimefree_off.go new file mode 100644 index 00000000000..3affe434f2f --- /dev/null +++ b/src/internal/goexperiment/exp_runtimefree_off.go @@ -0,0 +1,8 @@ +// Code generated by mkconsts.go. DO NOT EDIT. + +//go:build !goexperiment.runtimefree + +package goexperiment + +const RuntimeFree = false +const RuntimeFreeInt = 0 diff --git a/src/internal/goexperiment/exp_runtimefree_on.go b/src/internal/goexperiment/exp_runtimefree_on.go new file mode 100644 index 00000000000..176278b5425 --- /dev/null +++ b/src/internal/goexperiment/exp_runtimefree_on.go @@ -0,0 +1,8 @@ +// Code generated by mkconsts.go. DO NOT EDIT. + +//go:build goexperiment.runtimefree + +package goexperiment + +const RuntimeFree = true +const RuntimeFreeInt = 1 diff --git a/src/internal/goexperiment/flags.go b/src/internal/goexperiment/flags.go index 07aa1d0aeed..b3a3c8a4974 100644 --- a/src/internal/goexperiment/flags.go +++ b/src/internal/goexperiment/flags.go @@ -113,6 +113,9 @@ type Flags struct { // platforms. RandomizedHeapBase64 bool + // RuntimeFree enables the runtime to free and reuse memory more eagerly in some circumstances with compiler help. + RuntimeFree bool + // SizeSpecializedMalloc enables malloc implementations that are specialized per size class. SizeSpecializedMalloc bool