[5.6] Event wildcard listeners cache to save on string operations #23299
+30
−4
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi!
Str::is
is relatively expensive operation, which significantly slows down request, when goes in the number of dozens of thousand calls. UnfortunatelyDispatcher::getWildcardListeners
method calls it arbitrary number of times (depends on how many wildcard listeners of any kind you registered in your app) for every single event being fired.It may not be significant for ordinary webpage, but it is worth the effort in the high volume & data heavy API, where simple
Database\Connection::logQuery
(without any listener registered, ie. without any action taken) may causeStr::is
to be called thousands of times, thus slowing down API request by 5-10% in my example.This PR introduces instance based cache, which does the following:
getWildcardListeners
callBelow excerpt from blackfire showing the difference in example call.
after 84ms:
before 364ms: