Split from #3155568: Filter by bundle in EntityConverter route param converter.
Problem/Motivation
In #3155568: Filter by bundle in EntityConverter route param converter we've discovered that you cannot properly deprecate a class of a route access checker because the service is instantiated even no route is using it. Instantiating such a services is useless and has a performance cost. Fixing this issue might not bring signifiant performance improvement but it's still a win.
Steps to reproduce
n/a
Proposed resolution
- Static access checkers: Delay the instantiation of the access checker service until the point where we test if the checker is applicable to a certain route. In this way we are only instantiating services that are in use by defined routes.
- Dynamic access checkers: Right now the instantiation of all access checker services helps differentiate between static and dynamic services as we check if instance implements a certain interface (see
CheckProvider::loadDynamicRequirementMap()
). But we can do this when compiling the container rather than on runtime. Collect all service IDs of dynamic access checkers into a container parameter (dynamic_access_check_services
) and use it inCheckProvider
. When rebuilding the container is always better than at runtime.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
New array container parameter dynamic_access_check_services
Release notes snippet
n/a
Issue fork drupal-3183036
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
claudiu.cristeaAdded #3155568: Filter by bundle in EntityConverter route param converter as related issue.
Comment #4
claudiu.cristeaComment #6
jibranWhat a beauty of a patch. Do we need to document the container parameter somewhere? Should we collect before and after stats?
Comment #7
claudiu.cristea@jibran
Are there other "hidden" container parameters documented? I can do it, but not sure where. But I've already added this comment:
Should I expand it with an explanation about its scope?
If you mean "static" by "stats", I guess it's not important. Right now is after. Moving it before does it change something?
Comment #8
jibranHehe, I do mean stats. As it is a performance issue. It would be good to look at the before and after numbers for this patch.
Comment #9
jibranPlease see top of
core.services.yml
.Comment #10
claudiu.cristea@jibran
Well, as I said in the IS, I don't think the performance will increase too much. It might even show no improvement as in core we don't have access checked not used by routes. However, I'll try to create a benchmark scenario.
I think
app.root
andsite.path
are there because they are meant to be used by 3rd party code. But there are also those hidden parameters, which have an internal purpose. Normally we don't want to expose them because they are used only by core and they don't have a "public" value:authentication_providers
,twig_extension_hash
,language.default_values
,cache_contexts
,cache_bins
,cache_default_bin_backends
,main_content_renderers
,container.modules
,install_profile
,container.namespaces
,persist_ids
and so on... All these are are container parameters but they are not meant to be used by developers in 3rd-party code. They are only for internal usage. The same is fordynamic_access_check_services
.Comment #11
Berdircache_default_bin_backends is an interesting example: #2363351: Cached services can't be used in service providers/modifiers but I assume this doesn't apply here. Agreed that internal properties that aren't mean for configuration but just a sort of cache don't need to be added to the core.services.yaml
Also think this doesn't need profiling, it is only called during a router rebuild and there's no way that even a handful of services that we don't load is a measurable gain.
Maybe just remove both the needs profiling and performance tag which I think is slightly misleading. You can't claim performance gains without proving it, but that's not the goal here anyway, the main thing is being able to properly deprecate access checks.
Comment #12
claudiu.cristeaRemove tags
Comment #14
catchCommitted f992a8b and pushed to 9.3.x. Thanks!