Jump to content

Performance question: Hooking on method with multiple functions


Juergen
 Share

Recommended Posts

Hello @ all

I am using a lot of hooking of methods and I want to optimize the performance of a module a little. 

In my case I use the following Hooks inside my modules init() method:

public function init()
{
  $this->addHookBefore('Page::render', $this, 'function1');
  $this->addHookBefore('Page::render', $this, 'function2');
  $this->addHookBefore('Page::render', $this, 'function3');
  $this->addHookBefore('Page::render', $this, 'function4');
}

As you can see, I am always hooking the same method (Page::render) to run different functions. The functions itself are declared outside of the init() method.

My question:

Would it have an impact on the performance if I would fe summarize function1 to function4 into one function (see below) or does it not matter?

public function init()
{
	$this->addHookBefore('Page::render', $this, 'summarizeFunction');
}


protected function summarizeFunction()
{
      $this->function1();
      $this->function2();
      $this->function3();
      $this->function4();
}

As you can see, I have only 1 hook left, that hooks into Page::render - not 4 as before.

I have not try it, if there would be a significant performance boost or not. I only want to ask some other devs if they have experiences if this could be optimize the performance a little bit or not.

Best regards

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...