zendframework/zf2 — pull request #728 by weierophinney (2012-01-12 19:43:54+00:00)
Title: Feature/event manager improvements

This is a first stab at improving performance within the EventManager.

The changes include four BC breaks:

* CallbackHandler::__construct() no longer takes an $event argument; any metadata should now be passed to the $metadata (second) argument.
* Along the same lines, the CallbackHandler::getEvent() method was removed; use getMetadatum('event') instead (more below).
* CallbackHandler::getOptions/getOption were renamed to getMetadata/getMetadatum to provide a more accurate semantic
* The only validation being done on callbacks in CallbackHandler is whether or not they pass is_callable(). Furthermore, the class no longer lazy instantiates objects if the provided callback is declared statically but refers to an instance method. This simplifies logic and provides a performance boost. If such callbacks are encountered, PHP will provide an E_STRICT notice at the least, and an E_FATAL if the method refers to $this.

Also, internally, CallbackHandler::call() now uses call_user_func() for up to 3 arguments, and only results to call_user_func_array() when more than 3 arguments are reached.

Finally, I added __invoke(), which proxies to call(), to simplify usage of the CallbackHandler.

All classes consuming it have been updated at this time.

Performance benefits are not huge, but I measured the following:

* Attaching listeners now takes ~20% longer, as we validate immediately.
* Triggering listeners now takes ~25% less time.
* Overall performance when triggering a given listener only once takes <5% less time.

So, performance gains are not huge, but the code is now simpler and more semantic.