Use service closures in early request event subscribers

Created on 16 August 2025, about 2 months ago

Problem/Motivation

Child of πŸ“Œ Explore using more service closures to break deep dependency chains and load fewer services Active

Some request event subscribers such as options_request_listener and maintenance_mode_subscriber have deep DI chains that they only use in exceptional cases.

options_request_listener is only active on OPTIONS requests and maintenance_mode_subscriber only if the site is in maintenance mode.

Those dependencies will almost certainly still be used, but there will be cases where pushing them back is enough for some gains, for example if redirect_leading_slashes_subscriber does an early return.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component

base system

Created by

πŸ‡¨πŸ‡­Switzerland berdir Switzerland

Live updates comments and jobs are added and updated live.
  • Performance

    It affects performance. It is often combined with the Needs profiling tag.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @berdir
  • Merge request !13012Updaate request subscribers to use closures β†’ (Open) created by berdir
  • Pipeline finished with Failed
    about 2 months ago
    Total: 178s
    #574342
  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    I looked for others than those two examples, but these seem like the only quick wins. There are others that can be investigated, but for them, it's then services that they inject that we can possibly optimize, such as session manager (database), state (lock), cache tag invalidation (all cache bins that would get called on an invaidation), but I think that's out of scope. Probably better to do this piece by piece.

    The result, see also attached files:

    This is frontpage of standard profile, not logged in, with disabled page cache.

    url_generator moved far down, it's only initialized as part of the is frontpage cache context for the breadcrumb. Wondering if we really need that there.

    I didn't do BC because these are event subscribers.

    I did check blackfire as well, but there is no meaningful difference as those things are still needed for this scenario

  • Pipeline finished with Failed
    about 2 months ago
    Total: 290s
    #574345
  • The Needs Review Queue Bot β†’ tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    Fixed phpcs.

  • Pipeline finished with Success
    about 2 months ago
    Total: 781s
    #574540
  • Pipeline finished with Failed
    about 2 months ago
    Total: 316s
    #574782
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Can we update the summary with the 2 services that are being targeted. And maybe something similar to the META where the previous chain was router_listener -> router -> router.no_access_checks -> url_generator -> renderer -> theme.manager -> theme.registry -> extension.list.module and is now xyz

  • πŸ‡¨πŸ‡­Switzerland berdir Switzerland

    the before/after is in comment #1, with a screenshot of the diff, because it's really only readable with a colored word diff.

    I updated the title, but there isn't a whole lot more that can be put in the issue summary.

    The one question where we need an answer if if/how we want to do BC for this case. Event subscribers are explicitly excluded by the BC policy, so maybe the answer for this one is, no BC necessary.

  • Pipeline finished with Success
    about 1 month ago
    Total: 742s
    #588343
Production build 0.71.5 2024