[5.6] Event wildcard listeners cache to save on string operations#23299
Merged
taylorotwell merged 1 commit intolaravel:5.6from Feb 26, 2018
Merged
Conversation
…sive Str::is calls, which usually goes in dozens of thousands
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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::isis relatively expensive operation, which significantly slows down request, when goes in the number of dozens of thousand calls. UnfortunatelyDispatcher::getWildcardListenersmethod 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::isto 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:
getWildcardListenerscallBelow excerpt from blackfire showing the difference in example call.
after 84ms:

before 364ms:
