framework
framework copied to clipboard
Feature/hooks argument count calculator
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);
]);
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 ?
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
@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 :
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)