I'm working on porting over some Drupal 6 custom modules that another developer wrote, and I'm coming across some hooks that are, with the exception of comments, completely empty. I'm likely going to clean these out, for the sake of readable code, but I was curious if I would get any form of performance increase out of it.

  • Having more readable code will certainly improve your performance as a developer. That by itself is enough reason to clean them out. Other than that, I don't expect that you will be able to measure an increase in performance. Jun 19, 2013 at 19:10

1 Answer 1


I suspect I have been guilty of deploying code with empty hooks. Often, I will stub out hooks for debugging purposes, so I don't have to clear cache in order to dpm() something at the point I need. Ideally, though, dead code should be removed.

If you remove an empty hook, you will

  • Save a small amount of database space from the hook being saved in the registry. I think it will save one row.
  • Save a small amount of memory in APC.
  • Save some query memory and some PHP memory from reading in that row from the registry
  • Save a few CPU cycles from having a module_invoke_all() call something that does nothing.
  • Potentially save you some headache of having dead code in a file.

If you have the time, and have a site that works, there should be no harm in removing these hooks. Just test it to be positive.

Whether you have a meaningful performance impact is really debatable.

In the case of cached pages, the only hook that fires is hook_boot(). There will be some overhead from the bootstrap process reading in an extra hook from the registry. I seriously doubt this is measurable, though.

For authenticated access, or non-cached pages, the hook may run if the invoker runs. In other words, a hook_init() will always run, but a hook_node_insert() will only run if you actually save a new node. Even in this case, I doubt that you will have any meaningful impacts. Actually profiling this would be an interesting exercise, though.

TL;DR, there should be no harm in removing them, but you will probably not notice them gone.

  • 1
    Small note - removing them may be a problem if one does not regenerate caches after that operation. Having non-existent hooks in registry is a problem. Short lived, self fixing one, but good reason not to do this in high traffic time.
    – Mołot
    Jun 20, 2013 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.