Problem/Motivation

This is a micro-optimisation but we're making thousands of calls to \Drupal\Component\DependencyInjection\Container::get() when we return an uncached page and on every call we do

    if ($this->hasParameter('_deprecated_service_list')) {
      if ($deprecation = $this->getParameter('_deprecated_service_list')[$id] ?? '') {
        @trigger_error($deprecation, E_USER_DEPRECATED);
      }
    }

which we actually only need to do once when we instantiate the service.

Steps to reproduce

Get any service from the container twice.

Proposed resolution

Move the code to after the early returns. On a post request from the autosave module this reduces the calls to Drupal\Component\Dependency…tion\Container::getParameter() from 2890 to 378. Note this is a micro-optimisation because the calls are very cheap.

Remaining tasks

User interface changes

None

Introduced terminology

N/a

API changes

None

Data model changes

None

Release notes snippet

N/a

Issue fork drupal-3560108

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

alexpott created an issue. See original summary.

alexpott’s picture

Issue summary: View changes
Status: Active » Needs review
alexpott’s picture

Issue summary: View changes

smustgrave’s picture

Appears to be 1 suggestion in the MR @alexpott thoughts?

alexpott’s picture

I think the suggestion broke the MR :)

" This test is not expected to perform assertions but performed 1 assertion"

alexpott’s picture

I've reverted @longwave's suggestion - this should be all good now.

longwave’s picture

Oops although it would be good to know what that is as tests should not assert by default, which is why that method exists!

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Seems feedback for this one has been addressed then:)

  • catch committed 7e9eb086 on 11.x
    task: #3560108 Do not make 1000s of calls to get...
catch’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +Needs followup

This looks good.

Tagging for needs follow-up to see if we can figure out how to make @longwave's suggestion work or why it definitely can't work.

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.

Status: Fixed » Closed (fixed)

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