Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Motivation: speed up watchdog calls
watchdog uses module_implements, which is totally cached and knows that module_hook exists. module_invoke goes and calls module_hook which does another function_exists.
Since already know the function exists, how about just calling the function?
Comments
Comment #2
hefox CreditAttribution: hefox commentedGuess I could end the line with ;
Comment #3
marcingy CreditAttribution: marcingy commentedLooks good.
Comment #4
webchickMakes sense to me.
Committed and pushed to 8.x. Moving to 7.x for backport and adding some tags.
Comment #5
hefox CreditAttribution: hefox commented:)
Comment #6
hefox CreditAttribution: hefox commentedComment #7
tstoecklerSorry to re-open this, but it seems since nothing is done with the return value of the function call, a simple
module_invoke_all('watchdog', $log_entry)
would be enough.module_invoke_all()
does the additionalfunction_exists()
as well, but at least it would be in-line with code elsewhere. We should then discuss whether to remove thatfunction_exists()
frommodule_invoke_all()
in a follow-up issue. That would be a performance improvement across core. Also, someone should probably dig where and why this code was introduced, i.e. if this was intentional for some reason.Edit: Fix arguments in example code.
Comment #8
hefox CreditAttribution: hefox commentedThat was my first thought. My reasoning to do this instead:
1) Module_invoke_all uses call_user_func_array, which is significantly slower than $function()
2) Don't need any of the extra logic about return value/array_merge that module_invoke_all adds so might as well not do any extra.
#329012: Remove call_user_func_array() from ModuleHandler::invoke() + invokeAll() is issue to optimize module_invoke_all and does include the removal of function_exists (when that lands, reason 2 above is still the case).
(note: Can look to see how other's are using module_implements solo style by looking at http://api.drupal.org/api/drupal/core!includes!module.inc/function/calls... -- it is true most that are using it alone want to use the return value and add module implementing specific information)
Comment #9
hefox CreditAttribution: hefox commentedI did some benchmarking like stuff a few weeks ago and concluded the savings isn't really worth it, so patch to change it to module_invoke_all (untested) attached
I did not touch
it looks like module_implements has moved to the same file as watchdog, so is there any reason for this function_exists?
Comment #10
ParisLiakos CreditAttribution: ParisLiakos commentedNo logger applies to D8, hook_watchdog is gone
Comment #11
mgiffordreroll.
Comment #12
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae commentedPatch #11 still applies but with offset so I have re-rolled the same.
Comment #17
dagmarMoved to
dblog.module
for future triage.Comment #18
joseph.olstadDone in D8. So green light for D7Patch #12 still applies but with offset so I have re-rolled the same.***EDIT*** David Rothsteins patch below is the preferred.
Comment #19
David_Rothstein CreditAttribution: David_Rothstein as a volunteer commentedShouldn't we change the function_exists() call earlier in watchdog() to check the function that we're now actually calling? See attached.
Otherwise, this looks fine to me and is a nice code cleanup, although I assume any performance benefit here is very very minor.
Comment #20
PolTested locally, working super fine.
Comment #21
joseph.olstadyes David Rothstein to the rescue again
put it in, creds to David!
Slam dunk this.
Comment #22
PolComment #23
joseph.olstadBumping to 7.61. This didn't make it into 7.60
Comment #24
joseph.olstadComment #25
joseph.olstadComment #27
PolPatch has been committed, thanks !