Improve memory consumption by using static resolve and reject callback without binding to promise #116
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.
This builds on top of the implementation approach in #115 and the ideas discussed in #46.
The
$resolve
and$reject
callbacks passed to the resolver and cancellation functions of each promise now no longer cause a cyclic garbage reference in any exception trace as discussed in #46. This builds on top of the work done in #113. If you do not access any arguments, this PR has no effect (also no performance or memory penalty).If you do access any of the arguments, you no longer have to care about these functions memory wise, as they will no longer cause a cyclic garbage reference. A similar patch has been introduced for the
$progress
callback in #115 and this means this now consistently applies to all callbacks.Invoking the benchmarking example from #113 shows that this has little effect on performance (1M invocations that do no use arguments show no performance improvements, 1M invocations that do use arguments show a ~4% performance degradation).
This PR actually includes a test that shows how garbage memory references are no longer an issue in any supported PHP version and how these functions no longer cause any such references on their own (unlike the previous test in #115 this means that this requires no effort on the consumer side anymore).