reactphp / promise

Promises/A implementation for PHP.
https://reactphp.org/promise/
MIT License
2.38k stars 146 forks source link

Drop call_user_func calls in favour of calling callables directly #151

Closed WyriHaximus closed 4 years ago

WyriHaximus commented 4 years ago

With PHP 7 we can call callables directly rather then wrap it in a costly extra function call.

edhelas commented 4 years ago

Did you noticed some performances improvement with that change ?

WyriHaximus commented 4 years ago

@clue @edhelas Haven't ran any benchmarks against it. But essentially this should save us a function call wrapping another function call. Unless PHP has changed something, optimising this in a way it doesn't impact as much as it used to do this is still aesthetically more please IMHO.

WyriHaximus commented 4 years ago

@clue @edhelas on run the following benchmark using phpbench:

<?php

namespace foo {
    /**
     * @Revs(1000)
     * @Iterations(100)
     */
    class MixedBench
    {
        private $f;

        public function __construct()
        {
            $this->f = function () {
                return true;
            };
        }

        public function benchCallUserFunc()
        {
            \call_user_func($this->f);
        }

        public function benchPHP7()
        {
            ($this->f)();
        }
    }
}

The results show a slightly faster execution when calling it directly: image