Skip to content

Improve memory consumption for pending promises by using static internal callbacks without binding to self - #124

Merged
jsor merged 2 commits into
reactphp:2.xfrom
clue-labs:static
Jun 13, 2018
Merged

Improve memory consumption for pending promises by using static internal callbacks without binding to self#124
jsor merged 2 commits into
reactphp:2.xfrom
clue-labs:static

Conversation

@clue

@clueclue commented Jun 12, 2018

Copy link
Copy Markdown
Member

All previous changes that landed in https://github.com/reactphp/promise/releases/tag/v2.6.0 improved memory consumption for settled promises somewhat. Similarly, this PR addresses memory consumption for pending promises that are no longer referenced.

<?phpuseReact\Promise\Promise;
require__DIR__ . '/vendor/autoload.php';
for ($i = 0; $i < 1000000; ++$i) {
$promise = newPromise(function () { });
$promise->then('var_dump');
unset($promise);
}
var_dump(memory_get_usage());
var_dump(gc_collect_cycles());

Initially this peaked somewhere around 8 MB on my system taking 4s. After applying this patch, this script reports a constant memory consumption of around 0.6 MB taking 1.8s

Note that this PR does not resolve all unexpected memory issues. However, it addresses a rather common problem for some consumers of this library and makes many of the higher level work-arounds obsolete. My vote would to be get this in here now as it addresses a relevant memory issue and eventually address any additional issues on top of this. :shipit:

Builds on top of #123

@jsor
jsor merged commit 9bd9d48 into reactphp:2.xJun 13, 2018
@clue
clue deleted the static branch June 13, 2018 06:19
@clueclue mentioned this pull request Jun 7, 2022
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@clue@jsor@WyriHaximus