WyriHaximus ยท GitHub

@WyriHaximus

Copy link Copy Markdown

Member

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

@WyriHaximus

@WyriHaximus

@edhelas

Copy link Copy Markdown

Did you noticed some performances improvement with that change ?

jsor

jsor approved these changes Nov 25, 2019

clue

clue approved these changes Nov 26, 2019

@clue clue left a comment

Copy link Copy Markdown

Member

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 Copy Markdown

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 Copy Markdown

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

WyriHaximus deleted the drop-call-user_func-in-favour-of-calling-callables-directly branch

November 30, 2019 22:04

Read the original on github.com โ†—