framework icon indicating copy to clipboard operation
framework copied to clipboard

Feature/hooks argument count calculator

Open ogorzalka opened this issue 2 years ago • 4 comments

Hi Julien,

It's a small update of the Hook functionnality provided by Themosis allowing not to have to define the number of arguments in the call to the Action or Filter class. It is based on the principle of ReflectionClass.

Exemple :

Filter::add('foo', function($arg1, $arg2, $args3) {
    do_somethind($arg1, $arg2, $arg3);
]);

ogorzalka avatar Apr 04 '22 05:04 ogorzalka

I kind of like the automation idea, will review this later :) Just wondering if there is any performance issue by doing a reflection for a so small enhancement. Do you have any input on this ?

jlambe avatar Apr 04 '22 08:04 jlambe

Hi @jlambe

I think the performance impact is negligible, but I will perform a comparative test with blackfire with the old version and the new one :)

I'll let you know

ogorzalka avatar Apr 04 '22 08:04 ogorzalka

@jlambe I have just performed a first benchmark based on 100,000 add_action calls by testing the WP version, the original version of Themosis and the version allowing the number of arguments to be retrieved automatically. Here are the results:

WordPress (original)        Execution time : 0.2006561756134 seconds
Themosis Hook (original)    Execution time : 0.46634101867676 seconds
Themosis Hook (modified)    Execution time : 0.68220281600952 seconds

Graph datas :

image

ogorzalka avatar Apr 04 '22 11:04 ogorzalka

I just updated the code and the performance results are better :)

WordPress (original)        Execution time : 0.2185001373291 seconds
Themosis Hook (original)    Execution time : 0.43095987319946 seconds
Themosis Hook (modified)    Execution time : 0.49028398513794 seconds

I also changed the add_action call to add_filter inside the ActionBuilder (add_action is a shortcut for add_filter)

ogorzalka avatar Apr 04 '22 12:04 ogorzalka