After #2336597: Convert path aliases to full featured entities gets in we must reduce the number of queries in PathFieldItemList as suggested in #2511968-47: Path field should fall back to language neutral aliases (also makes this happen for the form widget!):

@Berdir:

I'm wondering if this could be done like the main alias lookup. Look for both language specific and neutral alias in a single load, if there is more than one alias, prefer the one with the matching language.

@amateescu:

That would be very easy to do after #2336597: Convert path aliases to full featured entities since we'll be able to use an entity query with an OR condition on the langcode field

Comments

zaporylie created an issue. See original summary.

wim leers’s picture

Title: Optimize alias lookup and load in PathFieldItemList » [PP-1] Optimize alias lookup and load in PathFieldItemList
Issue tags: +Performance
berdir’s picture

> That would be very easy to do after #2336597: Convert path aliases to full featured entities since we'll be able to use an entity query with an OR condition on the langcode field

I disagree with that.

Path aliases being an entity or even stored in the database is an implementation detail, this is a pluggable interface, they could actually be stored in MongoDB, Redis or some other backend.

amateescu’s picture

I think that means you disagree entirely with #2233595: Deprecate the custom path alias storage?

berdir’s picture

I didn't look at it yet in depth. The entity system itself is an abstraction too, so arguably, we are deprecating a custom storage system with a more general one, so that should be OK :) And we might to keep a limited API on top of that, because I would expect that an entity query + entity load is going to be several times slower than a simple SQL query that just fetches exactly the value that it needs. And there's actually a ton of additional cache logic on top of that with prefetching and what not, but I suppose that would remain.

I did something similar in redirect.module, which are also entities, I added a service/method (\Drupal\redirect\RedirectRepository::findMatchingRedirect) that bypasses the entity query API because that was *way* faster than an entity query. In that case, I still used a regular entity load on a match then, because performance for *that* isn't that relevant then, only the query that needs to run on *every* request was.

However, the alias system is different because having a result isn't the exception, for most sites its the default, so loading the alias needs to be as fast as possible as well. Not just that, we often do dozens of additional lookups on a patch to resolve aliases for all the URL's that we are generating and again expect lots of matches there too.

So my main point for that issue is that we spent *weeks* optimizing that as much as we could and we will have to be very, very careful to avoid performance regressions (or keep them to a minimum) in exchange for fancy features or simply removing code :)

And going back to this issue, using the entity query system directly would only be an option for 9.x as mentioned above.

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.

chris matthews’s picture

Status: Postponed » Active

#2336597: Convert path aliases to full featured entities is fixed, so back to Active (no patch)

wim leers’s picture

Title: [PP-1] Optimize alias lookup and load in PathFieldItemList » Optimize alias lookup and load in PathFieldItemList

🥳

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.

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.

amateescu’s picture

Status: Active » Closed (outdated)
Related issues: +#2233595: Deprecate the custom path alias storage

This was fixed in #2233595: Deprecate the custom path alias storage where PathFieldItemList uses a single alias repository query in ::computeValue().

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

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

Maintainers, please credit people who helped resolve this issue.