]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: add GOEXPERIMENT=runtimefree
authorthepudds <thepudds1460@gmail.com>
Sat, 25 Oct 2025 04:49:45 +0000 (00:49 -0400)
committert hepudds <thepudds1460@gmail.com>
Mon, 27 Oct 2025 04:49:25 +0000 (21:49 -0700)
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 <drchase@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/internal/buildcfg/exp.go
src/internal/goexperiment/exp_runtimefree_off.go [new file with mode: 0644]
src/internal/goexperiment/exp_runtimefree_on.go [new file with mode: 0644]
src/internal/goexperiment/flags.go

index f1a1d8632ef50729d7b450a1895b3425ce9f6d6f..31195f94c08c86a7a7e74222834e7c16431d866e 100644 (file)
@@ -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 (file)
index 0000000..3affe43
--- /dev/null
@@ -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 (file)
index 0000000..176278b
--- /dev/null
@@ -0,0 +1,8 @@
+// Code generated by mkconsts.go. DO NOT EDIT.
+
+//go:build goexperiment.runtimefree
+
+package goexperiment
+
+const RuntimeFree = true
+const RuntimeFreeInt = 1
index 07aa1d0aeed15d63b38286244fd9660b1dcb1fa2..b3a3c8a4974975daf25fbfd7a1f21142b91424b7 100644 (file)
@@ -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