Problem/Motivation

We have been slowly adding listeners to various kernel events over the last 2 years. That's fine, but as event subscribers register their own priority order it's not immediately obvious what the current order is, or if it's optimal.

Proposed resolution

Let's audit all kernel event subscribers and determine if we should rearrange the priority of any of them. In some cases, we may want to also move some post-routing request listeners to the controller event, per http://symfony.com/doc/current/components/http_kernel/introduction.html

After the controller callable has been determined, HttpKernel::handle dispatches the kernel.controller event. Listeners to this event might initialize some part of the system that needs to be initialized after certain things have been determined (e.g. the controller, routing information) but before the controller is executed.

Note: This issue is just about rearranging where certain actions fire. Changing what those listeners are doing is out of scope for this issue (except for syntax changes needed for changing the event, etc.)

Remaining tasks

1) Build a list of all request, controller, view, response, and terminate kernel event listeners/subscribers. That should be included in this issue summary, and potentially in a handbook page later.

2) Determine if we should move any of those listeners, either to change their priority or move some from request to controller.

3) Move anything we decide needs moving.

API changes

Any contrib modules that have a request listener with a sensitive priority MAY need to adjust as a result. However, that in most cases will be a one character change.

Comments

Crell’s picture

Of note: The router is currently request event, priority 32. 32 was chosen because that's what Symfony fullstack uses, and using that avoided a bikeshed discussion when the router/kernel were originally added. It has no special significance beyond that, so if we want to change it for some reason we can. (Although if there's no special reason to, having the same priority as Symfony fullstack is convenient.)

I think the initial audit here is a novice-friendly task.

dawehner’s picture

Yeah you should be able to pretty much extract the data from webprofiler module

wim leers’s picture

Note also that #2429617: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!) has to change some event subscribers' priorities in order to be able to do what it needs to do, because there is no gap left between them. A long time ago, it was assumed (for good reasons) that surely nothing ever would need to sit between them, but that was wrong. Let's fix that, and not make that mistake again :)

dawehner’s picture

I'm curious whether we should choose a range and then spread the core subscribers equally.

Crell’s picture

@dawehner: Now that we have (probably?) a final list of the listeners we'll have (although it sounds like Wim is adding one), that's reasonable to try and do. Certainly better than our previous strategy of "make this one 100,000 so it's really first!!!" :-) Say, space them every 10?

wim leers’s picture

10 seems sufficient, but 20 seems more prudent?

dawehner’s picture

What about 3.14?

wim leers’s picture

Let's go with 1.4142135623731.

lussoluca’s picture

I've done a quick patch to Webprofiler to also collect event priorities: #2513814: Add a priority column to the events list

wim leers’s picture

Issue tags: +Novice, +php-novice

@lussoluca++


Sorry for the distraction in #6/#7/#8 — that's my fault. 10 is fine. Let's just do this.

wim leers’s picture

@larowlan had an interesting idea over at #2429617-310: Make D8 2x as fast: Dynamic Page Cache: context-dependent page caching (for *all* users!):

side note: I wonder if its worth creating constants somewhere in the routing system - so we could do stuff like SomeRouteInterface::FORM_WRAPPER_DERIVATION - 1 which would make it clear that the subscriber went just before that particular instance.

jibran’s picture

+1 for the idea.

yched’s picture

SomeRouteInterface::FORM_WRAPPER_DERIVATION - 1 :

Sounds interesting in theory - but then in practice which are the ones worthy of having a constant, vs the ones that just position themselves around those constants, without defining a constant of their own ?

jibran’s picture

Why not define constants for all in core?

wim leers’s picture

#14: we can't have constants for everything in core, because some would be defined as OTHER_CONSTANT - X, with OTHER_CONSTANT also depending on another constant, etc.

That's equally unmaintainable.


Symfony's event system should not be using numeric priorities in the first place, but before and after relationships instead. Then we wouldn't have this problem.

dawehner’s picture

Well, on the other hand using before/after adds another level of coupling you ideally don't want to have. Ideally the numbers would outside of the actual executed class,
see #2023613: Move event registration from services.yml to events.yml

wim leers’s picture

Can you give an example of before/after being problematic?

In CSS/JS asset handling, we used weights in D<8. That caused nothing but pain and trouble. Thanks to dependencies (which are effectively "after" relationships), that's now mostly gone (since few things need "before" relationships, at least in the world of assets). You just need to explicitly before/after which specific things you want to run.

I don't see — yet — why that wouldn't also work for event subscriber ordering.

Crell’s picture

We've discussed before/after in the past. The graph dependency resolution it needs is non-trivial. Remember also that EventDispatcher allows you to add new listeners at any time, so complex precompilation as a requirement for functionality is a non-starter, and integer ordering is actually quite powerful. (Certainly better than module weights.) Also, many listeners don't actually care what order they're called in. The order is at best a performance optimization.

But all that is off topic. *All* we're doing here is auditing the current listeners. We just need someone to do that, or write the script to do that. No more. Any changes to how we define listener order are off topic.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Torenware’s picture

Issue tags: +Baltimore2017

This is an "auditing" task. Look at the issue summary, and do the first item to find out who is using what events (probably by searching in your text editor). Good novice issue if you're comfortable with PHP but new to Drupal contributing.

benjifisher’s picture

Issue tags: -Baltimore2017
dawehner’s picture

#2352351: Add before/after ordering to events provides some dependency based priority system.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ivan berezhnov’s picture

Issue tags: +CSKyiv18

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: -Novice, -

Is this a task that still needs to be done?

quietone’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Since there hasn't been confirmation, in the past 9 months, that this still needs to be done. I am closing this issue.

If there is work to do here, then either re-open the issue or open a new issue and reference this one. If the choice is to use this issue then add a comment change make sure to change the issue status to 'Active'.