-
-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve memory consumption by using static child canceller callback without binding to parent promise #117
Merged
+48
−6
Conversation
This file contains 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
jsor
reviewed
May 4, 2018
src/Promise.php
Outdated
|
||
if ($this->requiredCancelRequests <= 0) { | ||
$this->cancel(); | ||
return new static($this->resolver($onFulfilled, $onRejected, $onProgress), self::parentCancellerFunction($parent)); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CS: missing linebreak before the closing }
of the method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for spotting, fixed!
This was referenced May 4, 2018
jsor
approved these changes
May 6, 2018
WyriHaximus
approved these changes
May 6, 2018
jsor
added a commit
to jsor-labs/pact
that referenced
this pull request
May 16, 2018
This incorporates the work done by @clue in the following PR's for reactphp/promise: * reactphp/promise#115 * reactphp/promise#116 * reactphp/promise#117 * reactphp/promise#118 * reactphp/promise#119 Co-authored-by: Christian Lück <christian@lueck.tv>
jsor
added a commit
to jsor-labs/pact
that referenced
this pull request
May 16, 2018
This incorporates the work done by @clue in the following PR's for reactphp/promise: * reactphp/promise#113 * reactphp/promise#115 * reactphp/promise#116 * reactphp/promise#117 * reactphp/promise#118 * reactphp/promise#119 Co-authored-by: Christian Lück <christian@lueck.tv>
This was referenced Jun 9, 2018
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.
Calling
cancel()
on a child promise that follows its parent promise now no longer causes a cyclic garbage reference in any exception trace as discussed in #46. This builds on top of the implementation approach in #115 and #116 and the ideas discussed in #46.The gist here is that
$promise->then()->cancel()
now no longer causes any unexpected cyclic garbage reference and consumers of this package do not need to take special care of this.Similar patches have been introduced with #115 and #116 to implement a similar logic for the resolution and cancellation callbacks and this PR takes advantage of this for its internal implementation.
Invoking the benchmarking example from #113 shows no effect because it does not use child promises. After patching this to use
$promise->then()->cancel()
instead of$promise->cancel()
, this shows a very significant performance and memory improvement! Initially this peaked somewhere around 15 MB on my system taking 24s. After applying this patch, this script reports a constant memory consumption of around 0.6 MB taking 5s.This PR actually includes a test that shows how garbage memory references are no longer an issue in any supported PHP version and how cancelling a child promise no longer causes any such references on its own (this means that this requires no effort on the consumer side).