Modify

Opened 3 years ago

Last modified 2 years ago

#2448 new Aufgabe

Performance: Nutzung von "variadic functions" (splat-Operator) anstatt call_user_func_array()

Reported by: noRiddle Owned by: somebody
Priority: normal Milestone: modified-shop-2.0.9.0
Component: Shop Version: 2.0.7.2
Keywords: Cc:
Blocked By: Blocking:

Description

In den klasseModule.class.php für die Klassenerweiterungen wird call_user_func_array() verwendet.
Nach einigen benchmarks die man im I-Net findet wären "variadic functions" schneller, und zwar gar nicht unerheblich schneller.
Siehe z.B.: PHP-Manual
oder: Drupal issues

Ich werde bei Gelegenheit mal eine eigene Benchmark erstellen.

Beipielcode jetzt (aus productModules.class.php):

    function call_module_method()
    {
        $arg_list = func_get_args();
        $function_call = $this->function_call;
        if (is_array($this->modules)) {
            reset($this->modules);
            foreach($this->modules as $class) {
                if (is_callable(array($GLOBALS[$class], $function_call))) {
                    $arg_list[0] = call_user_func_array(array($GLOBALS[$class], $function_call), $arg_list); //Call the $GLOBALS[$class]->$function_call() method with $arg_list
                }
            }
        }
        return $arg_list[0]; //Returns only first parameter
    }

mit variadic (auch noch weniger Code):

    function call_module_method(...$arg_list)
    {
        $function_call = $this->function_call;
        if (is_array($this->modules)) {
            reset($this->modules);
            foreach($this->modules as $class) {
                if (is_callable(array($GLOBALS[$class], $function_call))) {
                    $arg_list[0] = $GLOBALS[$class]->$function_call(...$arg_list);
                }
            }
        }
        return $arg_list[0]; //Returns only first parameter
    }

Da ich's an der product-Klasse getestet habe fiel mir außerdem noch auf, daß man die Methode buildDataArray() auch mit Caching arbeiten könnte.
Auf manchen Seiten, wo Produkte mehrfach vorkommen, wegen Boxen in der linken Spalte oder Bestsellers, bringt das nochmal ein wenig.
Gehört eigtl. in ein Extra-Ticket, aber da es ebenfalls um Geschwindigkeit geht...

Gruß,
noRiddle

Attachments (0)

Change History (2)

comment:1 by Gerhard Waldemair, 2 years ago

Milestone: modified-shop-2.0.8.0modified-shop-2.0.9.0

comment:2 by noRiddle, 2 years ago

Das Caching mittels einer static Var für die Methode buildDataArray() könnte man vom eigtl. Thema losgelöst doch bereits sofort fixen...

Gruß,
noRiddle

Modify Ticket

Action
as new The owner will remain somebody.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.