Skip to content

Conversation

clue
Copy link
Member

@clue clue commented Jun 12, 2018

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.

<?php

use React\Promise\Promise;

require __DIR__ . '/vendor/autoload.php';

for ($i = 0; $i < 1000000; ++$i) {
    $promise = new Promise(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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants