Skip to content

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

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

Merged
merged 2 commits into from
Jun 13, 2018

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy