Skip to content
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

Drop call_user_func calls in favour of calling callables directly #151

Conversation

WyriHaximus
Copy link
Member

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

@edhelas
Copy link

edhelas commented Nov 24, 2019

Did you noticed some performances improvement with that change ?

Copy link
Member

@clue clue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM either way 👍

Do you happen to have any benchmarking results for comparison?

@WyriHaximus
Copy link
Member Author

@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
Copy link
Member Author

@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

@WyriHaximus WyriHaximus merged commit f2c6529 into reactphp:master Nov 30, 2019
@WyriHaximus WyriHaximus deleted the drop-call-user_func-in-favour-of-calling-callables-directly branch November 30, 2019 22:04
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.

None yet

4 participants