Conversation
a closure submitted to a pool travels as its compiled function, with every closure its body creates, serialized through the bytecode format and cached on the pool by compile name, plus its captures as a payload: use variables, $this, the scope markers, and for an arrow function the caller's variables its body names, snapshotted at submit because the vm resolves those at call time. each worker loads the code once and binds a fresh instance per task. by-reference captures are refused. closure and anonymous class ids come from a process-wide atomic now: worker threads compile their own bootstrap and load closures compiled on the main thread, so two compile units must never mint the same name
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.
Part of #68.
A closure submitted to a pool travels as its compiled function, with every closure its body creates, serialized through the bytecode format and cached on the pool by compile name, plus its captures as a payload:
usevariables,$this, the scope markers, and for an arrow function the caller's variables its body names, snapshotted at submit because the VM resolves those at call time from a frame that does not exist on the other thread. Each worker loads the code once and binds a fresh instance per task. By-reference captures are refused; captures follow the same transfer rules as arguments.Closure and anonymous class ids now come from a process-wide atomic. Worker threads compile their own bootstrap and load closures compiled on the main thread, so two compile units must never mint the same
__closure_N.Tests:
tests/workers/closures.phpinmake workers(use captures, arrow functions, static closures, bound$thiswith private access, closures creating closures, repeated submits, exceptions, coercion, refusals, a closure consuming a channel). The memory soak gains repeated closure submits.