reactphp / async

Async utilities and fibers for ReactPHP.
https://reactphp.org/async/
MIT License
204 stars 19 forks source link

Improve performance by avoiding unneeded references in `FiberMap` #88

Closed clue closed 6 months ago

clue commented 6 months ago

This change applies some performance improvements by avoiding unneeded references in the internal FiberMap. This is a purely internal change that comes with 100% code coverage and does not otherwise affect the public API, so it should be safe to apply.

This happens to show a ~10% performance improvement in my synthetic benchmark:

async(function () {
    $promise = resolve(42);
    $n = 10_000_000;

    for ($i = 0; $i < $n; ++$i) {
        await($promise);
    }
})();

// old: 3.9s
// new: 3.5s

(Also posted in https://twitter.com/another_clue/status/1793723464194638108)

This code path only affects v4, so there is no need to backport this to v3 or v2.

Builds on top of #55 and #20