Problem/Motivation

Drupal\Core\Theme\ComponentNegotiator::negotiate

Doing some profiling of Drupal CMS and I see a lot of memory usage from this method.

Seems to all be due to Drupal\Core\Extension\ExtensionList::getList which is called by Drupal\Core\Theme\ComponentNegotiator::maybeNegotiateByModule

I think the component negotiator probably needs its own cache so it doesn't need to load the full info for every module into memory on every request - but didn't read code yet.

This is also called by Drupal\Core\Extension\ThemeHandler::listInfo

Steps to reproduce

N/A

Proposed resolution

Move sorting of module components to the discovery phase and cache the result, then only themes need to be sorted at runtime.

Remaining tasks

None

User interface changes

None

Introduced terminology

None

API changes

None

Data model changes

None

Release notes snippet

None

CommentFileSizeAuthor
#8 3493813-nr-bot.txt91 bytesneeds-review-queue-bot

Issue fork drupal-3493813

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

catch created an issue. See original summary.

berdir made their first commit to this issue’s fork.

berdir’s picture

Status: Active » Needs review

Stumbled over this as well, thanks to #3500739: Aggregate cache operations per bin in performance tests to allow for more specific asserts

The module weight is stable, unlike the active theme, it doesn't change at runtime. We can sort the whole component list once by module weight and then negotiate doesn't actually need to do any negotiation, it can just return the first. We might need a cache tag on config:core.extension in case a module weight changes.

Also didn't check tests yet nor did I properly inject the module extension list.

ironnuts’s picture

Added a review comment to the MR.

ironnuts’s picture

Issue summary: View changes

Filled out the issue summary template.

berdir’s picture

Issue summary: View changes

Improved the comment and updated the cache assertions.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. 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.

e0ipso’s picture

It's been a while since I was in this code, but everything checks out. Bear in mind that I reviewed this on my phone without access to the full codebase.

It'd be nice to have @pdureau's confirmation.

vladimiraus made their first commit to this issue’s fork.

pdureau’s picture

Status: Needs work » Reviewed & tested by the community

Reviewed by @e0ipso.

Also reviewed by @grimreaper on behalf of @pdureau . It looks OK to us because the new logic seems better performance wise, but can we check a last thing before merging?

Is there a way to evaluate the performance change? Also, are we sure that there is no regression? Do the existing tests cover the scope impacted by this change?

berdir’s picture

The updated performance tests show that we no longer request that cache on that page, yes. We also have performance graphs that should show the memory savings over time once committed, but we do not assert on time/memory explicitly as it's too fragile.

  • catch committed bafbb294 on 11.x
    Issue #3493813 by berdir, vladimiraus, catch, oily, e0ipso, pdureau,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Thanks this looks great, and really nice that we have a way to test for it now, if not the memory improvement directly.

Committed/pushed to 11.x thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.