Problem/Motivation

Route preloading happens on any HTML request, even if no URLs would be generated. Not generating URLs actually is a fairly common scenario: for example those responses that can be served from Drupal 8's Dynamic Page Cache.

If the preloading would be triggered as part of the URL generator, we can avoid the preloading in those common scenarios where it is not necessary.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Issue fork drupal-2543016

Command icon 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

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new9.15 KB

Let's do it.

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.

markdorison’s picture

Version: 8.1.x-dev » 8.3.x-dev
Status: Needs review » Needs work

Patch no longer applies cleanly.

dawehner’s picture

This is doable during the 8.x.y. cycle.

wim leers’s picture

I do not fully understand what this patch is doing and why.

dawehner’s picture

Issue summary: View changes
catch’s picture

Issue summary: View changes
dawehner’s picture

Issue summary: View changes

Well, we actually check for HTML requests, see \Drupal\Core\Routing\RoutePreloader::onRequest

wim leers’s picture

Title: Move route preloading into the UrlGenerator » Move route preloading into the UrlGenerator: don't simply preload on every HTML request
Issue summary: View changes
Issue tags: -Needs issue summary update

Thanks, that helped! I clarified it further based on my new understanding. Feel free to correct if it's inaccurate.

catch’s picture

Yes that looks right (and sorry dawehner for the incorrect correction). There was a bit of discussion around this in #2508445: Cache the query in RouteProvider::preloadRoutes(). Still makes sense to me - it's the generator that needs the pre-loading, so it should do it.

dawehner’s picture

No worries, its also a good sign that hthe patch above didn't caused any failures. Given that there isn't really a big BC break, I'd argue

catch’s picture

Yes patch looks completely fine for a minor to me - just constructor arguments and a new protected method. The actual logic change shouldn't make any difference. If routes aren't pre-loaded we can still get them, just one at a time until that happens.

dawehner’s picture

Well, one could have replaced the event dispatcher and reload on fewer pages or so.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new9.24 KB

Here is a reroll.

Status: Needs review » Needs work

The last submitted patch, 14: 2543016-14.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new12.2 KB
new3.24 KB

This should be it.

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

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now 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.

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

berdir’s picture

This would be interesting. I've also noticed that the the list of routes that get preloaded can get really big in projects with a lot of additional routes. And most of those are not actually needed. Wondering if this would make sense as a cache collector, where we only load the routes we need per route name?

dawehner’s picture

@Berdir
How would you group the routes to be loaded?

berdir’s picture

based on the current route name I'd say, so all node pages would share the same cache. Would need to test a bit, but I suspect that this would result in 10% or less of the current pre-loaded list that is currently loaded, several hundred routes seems pretty common to have in that list.

berdir’s picture

Had a quick look at one large custom project, it is preloading 437 routes and strlen(serialize($routes)) is 679313 in the preload method. There are tons of views and page manager routes, even REST routes which I guess are rather unlikely to be linked.

wim leers’s picture

even REST routes which I guess are rather unlikely to be linke

They would indeed be very unlikely to get linked.

It seems to me that this could also use a heuristic, at least for the case of REST/JSON API/GraphQL routes since they're unlikely to be linked to: exclude routes routes that have a _format route whose value is not html.

dawehner’s picture

So if we would use a cache collector, wouldn't we not have to care about it at all? It would just store the needed routes over time and be done with it.

berdir’s picture

I guess we want to keep logic like the admin exclude because admins will probably require those frequently while other users don't?

Also not quite sure yet where and how the cache collector would live. Unlike this preloading, which can be a completely separate subscriber, a collector-based approach needs to know which routes were loaded, so we'd need something like a getLoadedRoutes or so?

dawehner’s picture

I guess we could write some decorator for the route provider?

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.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.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). 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.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new132 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

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

markdorison’s picture

Status: Needs work » Needs review
StatusFileSize
new11.87 KB

Re-rolled patch.

bhanu951’s picture

Assigned: Unassigned » bhanu951

bhanu951’s picture

StatusFileSize
new6.98 KB
borisson_’s picture

> Does it require BC Shim ? as this is not a public service.

This is a really good question. I think that we don't need the BC shim because of https://www.drupal.org/about/core/policies/core-change-policies/bc-polic....

catch’s picture

I re-read the discussion from five years ago, and I think if we end up with a working and viable patch here for the original approach, we should probably split the cache collector idea out to its own issue - that might be even better, but needs thought on exactly where to put it and how it would work.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

There are some open threads and a test failure in the MR.

smustgrave’s picture

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

berdir’s picture

Forgot/didn't find this issue, created a new one instead: #3503843: Remove automatic preloading of all "public" routes, cache routes in fast chained bin. Might be a duplicate, but I'm wondering there if we need preloading at all.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

berdir’s picture

Status: Needs work » Closed (duplicate)

We pretty much agree now to remove the preloading and change how we cache the routes, so closing this as a duplicate of #3503843: Remove automatic preloading of all "public" routes, cache routes in fast chained bin

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.