Problem/Motivation
I've been doing some Blackfire profiling lately and noticed SchedulerManager::getPlugins() being called 8 times in an add to cart request (via a JSONAPI endpoint).
This means 8 requests to Redis (which might not sound a lot), but it is unnecessary as we could simply retrieve the plugins once per request, and statically cache them in an array.
See the attached screenshot, won't be able to work on this today, but maybe in the upcoming days if the maintainers are interested.

I'm aware 5.81ms isn't a lot, but this is also a matter of reducing unnecessary calls to the cache backend (e.g: Redis which becomes a bottleneck in case of high traffic).
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | 3533739-5.patch | 6.31 KB | jsacksick |
| scheduler-manager-get-plugins.png | 29.8 KB | jsacksick |
Issue fork scheduler-3533739
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
jsacksick commentedComment #4
jsacksick commentedCurrently, when a provider is passed, the persistent cache is bypassed. With this change, we always use the static cache if present, then fallback to the persistent cache. The provider filtering is done after the fact. I think this makes more sense than bypassing the persistent cache entirely when a $provider is passed.
Comment #5
jsacksick commentedAttaching a static patch for use with composer.
Comment #6
jonathan1055 commentedThis looks interesting, thanks for working on it.
I've just merged #3446881: Undefined array key "translatable" when Language is enabled but not Content Translation and would like to tag a new release soon, so maybe we can get this improvement in too?
Comment #7
jsacksick commentedI think this is an interesting fix, the
getPlugins()method is called a lot and currently each call to that method will make a request to the cache backend (in my case Redis), For example, 8 cache get calls on a simple add to cart request.I'm actually wondering if the persistent cache fully makes sense here, because
doGetPlugins()calls$this->getPluginDefinitions();Which gets the definitions from the plugin manager:$this->pluginManager->getDefinitions();This invokes the
getDefinitions()method on theDefaultPluginManagerwhich has the following logic:So the plugin definitions already have static cache + persistent cache handling. So we define our own cache on top of the core cache handling.
Our own persistent cache probably still makes sense otherwise we'll perform the following logic over and over:
Comment #8
jonathan1055 commentedI notice you have fixed a dependency injection, but we have #3507012: Fix \Drupal calls should be avoided in classes, use dependency injection already, so I'd prefer if we keep this issue in scope. Was there a particular need for that to be fixed here? If not I will undo that, otherwise there will be a conflict.
Comment #9
jonathan1055 commentedI've merged in 2.x and resolved the conflict, so there's nothing more to do regarding #8.
Comment #11
jonathan1055 commentedMerged. Thank you very much for doing this work, it is a good improvement.