call_user_func_array() is substantially slower than calling a function directly. In fact, it's probably the slowest possible way to call a function. However, Drupal uses cufa()... a lot. All hook calls and theme calls involve multiple cufa() calls. Eeek! The only reason we can't use $function() is that we don't know in advance how many arguments a function is going to take, which means we need the indirect call.
Or do we?
If we accept 2 limitations, then we can switch to $function in several places:
1) An indirectly called function (hook or theme) may have no more than 10 (or some other arbitrary number) of arguments.
2) An indirectly called function will always be called with that same number of arguments, padded with NULL, with the unneeded ones just falling on the floor. That means we cannot rely on func_num_args()/func_get_args() there, which shouldn't be a problem with any current hook/theme implementations. We don't use those functions that much anyway.
The attached patch implements the above two limitations and then converts several cufa() calls along the critical path to $function calls. In my spot testing, thing seem to still be working. Yay! :-) Although it's only a few functions that change, they're all lines that are called dozens of times or more every page load so we're actually replacing hundreds of cufa() calls at runtime.
This does, of course, need a benchmarking guru.
FAILED: [[SimpleTest]]: [MySQL] 63,502 pass(es), 78 fail(s), and 9 exception(s). View
FAILED: [[SimpleTest]]: [MySQL] Drupal installation failed. View
FAILED: [[SimpleTest]]: [MySQL] Setup environment: Test cancelled by admin prior to completion. View
FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch drupal8.module-invoke.66.patch. Unable to apply patch. See the log in the details link for more information. View