diff --git a/src/runtime/gc_finalizer.go b/src/runtime/gc_finalizer.go index df3a4c6c6f..62b4c20b62 100644 --- a/src/runtime/gc_finalizer.go +++ b/src/runtime/gc_finalizer.go @@ -33,10 +33,6 @@ type finalizerEntry struct { fn interface{} } -// finalizerGCThreshold starts pressure GC when registrations indicate external memory pressure. -// Larger tables use a proportional threshold. Zero disables this trigger. -const finalizerGCThreshold = 32 - var ( finalizers *finalizerEntry // registered finalizers; a GC root that keeps fn values alive finalizerPending *finalizerEntry // finalizers whose object died, waiting to run diff --git a/src/runtime/gc_finalizer_nopressure.go b/src/runtime/gc_finalizer_nopressure.go new file mode 100644 index 0000000000..56bd424a07 --- /dev/null +++ b/src/runtime/gc_finalizer_nopressure.go @@ -0,0 +1,10 @@ +//go:build (gc.conservative || gc.precise) && runtime_nofinalizerpressure + +package runtime + +// finalizerGCThreshold is zero with the build tag runtime_nofinalizerpressure: +// finalizer registrations do not start a collection, and finalizers run after +// the collections the heap itself needs. For programs that register many +// finalizers and go idle often, such as syscall/js programs, where every +// js.Value registers one and every await is an idle. +const finalizerGCThreshold = 0 diff --git a/src/runtime/gc_finalizer_pressure.go b/src/runtime/gc_finalizer_pressure.go new file mode 100644 index 0000000000..500464681f --- /dev/null +++ b/src/runtime/gc_finalizer_pressure.go @@ -0,0 +1,7 @@ +//go:build (gc.conservative || gc.precise) && !runtime_nofinalizerpressure + +package runtime + +// finalizerGCThreshold starts pressure GC when registrations indicate external memory pressure. +// Larger tables use a proportional threshold. Zero disables this trigger. +const finalizerGCThreshold = 32