runtime: build tag to turn off the finalizer pressure GC - #5819
Open
joeblew999 wants to merge 1 commit into
Open
joeblew999 wants to merge 1 commit into
joeblew999 wants to merge 1 commit into
Conversation
…r pressure GC The scheduler runs a full collection whenever it goes idle and finalizerGCThreshold finalizers were registered since the last one. A syscall/js program registers a finalizer for every js.Value and goes idle at every await, so it collects at nearly every pause: 100 collections in 100 event-loop turns in the reproduction in tinygo-org#5800. The threshold already means 'off' when it is zero. This moves the constant into two files so that -tags=runtime_nofinalizerpressure selects zero. The default is unchanged. Updates tinygo-org#5800
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates #5800.
The problem. The scheduler runs a full collection whenever it goes idle and
finalizerGCThresholdfinalizers were registered since the last one. Asyscall/jsprogram registers a finalizer for everyjs.Valueand goes idle at every await, so it collects at nearly every pause. In a real program (an HTTP API on Cloudflare Workers) this was the largest single cost we measured: 38 to 71 ms of CPU per request with the trigger, 9 to 13 ms without, same heap.The change.
finalizerGCThresholdalready means "off" when it is zero. This moves the constant into two files, asbuild_asserts.go/build_noasserts.godo forruntime_asserts, so that-tags=runtime_nofinalizerpressureselects zero. The default is unchanged: nothing differs for a program built without the tag.Measured with the reproduction in #5800 (
-target wasm, run with Node; each of 100 rounds makes 40 JS values and waits once for the event loop):-tags=runtime_nofinalizerpressuretestdata/finalizer.go,finalizeridle.go,finalizerbits.go,finalizerinvariants.goandfinalizerlarge.go, built for wasm without the tag and run with Node, give their expected output.Open to a different shape. A tag is the smallest thing that lets a program opt out. If you would rather make the default cheaper for
syscall/jsprograms (counting only finalizers whose objects could have died, or scaling with heap use), I am glad to rework this, and the tag name is yours to choose.