Suggested commit message:

Issue #2474055 by pwolanin, dawehner, amateescu: Performance regression in contact_help()

In #2091395: Update hook_help for Contact module calls to the UrlGenerator were moved to the top of the contact_help() implementation

This looks like an optimization, but it's actually a performance regression since these are now called on every page on every invocation of hook_help()

We also need to add a test to prevent regressions by not allowing any UrlGenerator calls on non-matching invocations of hook_help

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because it's a performance regerssion
Issue priority Major because ... Critical/Not critical because ...

Comments

pwolanin’s picture

wim leers’s picture

Title: preformance regression in contact_help » Performance regression in contact_help()
Issue tags: +Performance
pwolanin’s picture

Status: Active » Needs review
Issue tags: -Performance +D8 Accelerate Dev Days
StatusFileSize
new2.73 KB

quick 1st pass.

pwolanin’s picture

Issue tags: +Performance

Need to figure out the regression test too

amateescu’s picture

Issue summary: View changes

This was found while pair-profiling with @dawehner, adding a suggested commit message to the IS.

fabianx’s picture

Not sure how we can do that (regression test), but this would be RTBC from my side.

Maybe a sub-classed UrlGenerator inserted into the Container in a web test, then calling $moduleHandler->invokeAll('help')?

dawehner’s picture

StatusFileSize
new534.4 KB
new4.14 KB
new1.42 KB

Here is a test ... the image is a prove that it actually works.

dawehner’s picture

StatusFileSize
new8.08 KB

I'm sorry, totally forgot the actual files

The last submitted patch, 7: 2474055-5.patch, failed testing.

jcnventura’s picture

The regression test should be a static analysis that hook_help implementations should only have whitespace (or comments) between the opening bracket and the switch statement. It is pointless to guard against each possible mistake.

I've created a coder code sniffer feature request about that.

amateescu’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/help/src/Tests/HelpEmptyPageTest.php
    @@ -0,0 +1,65 @@
    +   * Ensures that no hook_help() is called on a page without hook_help().
    

    I think we're testing that there's no routing activity, no?

  2. +++ b/core/modules/help/src/Tests/HelpEmptyPageTest.php
    @@ -0,0 +1,65 @@
    +    \Drupal::service('module_handler')->invokeAll('help', ['<front>', new RouteMatch('<front>', $route)]);
    

    The standard way to do this is a try / catch block with $this->fail() and $this->pass() :)

dawehner’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new8.09 KB
new601 bytes

Muh.

@amateescu took back point 2.

wim leers’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/help/tests/modules/help_test/src/SuperNovaGenerator.php
    @@ -0,0 +1,74 @@
    +class SuperNovaGenerator implements UrlGeneratorInterface {
    

    :D

  2. +++ b/core/modules/user/user.module
    @@ -1136,11 +1136,12 @@ function user_role_change_permissions($rid, array $permissions = array()) {
     function user_role_grant_permissions($rid, array $permissions = array()) {
       // Grant new permissions for the role.
    -  $role = Role::load($rid);
    -  foreach ($permissions as $permission) {
    -    $role->grantPermission($permission);
    +  if ($role = Role::load($rid)) {
    +    foreach ($permissions as $permission) {
    +      $role->grantPermission($permission);
    +    }
    +    $role->save();
       }
    -  $role->save();
     }
    

    Seems unrelated?

Other than that, looks ready.

dawehner’s picture

Status: Needs work » Needs review

Seems unrelated?

Well, a) its the right thing to do, certainly b) its causing failures in the kernel test, if you don't check it.

wim leers’s picture

Status: Needs review » Reviewed & tested by the community

Alright, then this is ready!

amateescu’s picture

I agree, RBTC +1 :)

fabianx’s picture

RTBC++

catch’s picture

Status: Reviewed & tested by the community » Needs work

This needs a comment in hook_help() to explain why we build the links in two places. The test will stop a patch from getting committed, but I can see it being confusing and people trying to revert this.

wim leers’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new8.65 KB
new587 bytes

Comment added.

  • alexpott committed 6e466e4 on
    Issue #2474055 by dawehner, pwolanin: Performance regression in...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Looks like Alex got this one.

Status: Fixed » Needs work

The last submitted patch, 19: 2474055-19.patch, failed testing.

tim.plunkett’s picture

Status: Needs work » Fixed

Thanks testbot.

znerol’s picture

Status: Fixed » Closed (fixed)

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