Remove isFront from system_js_settings_alter()

Created on 12 June 2015, over 9 years ago
Updated 21 August 2023, about 1 year ago

Problem/Motivation

template_preprocess_html() takes 13ms on my machine with the standard profile, and it's uncacheable at the moment.

system_js_settings_alter() is responsible for over 10% of that time. Quite a lot of that is URL manipulation that's been carried over more or less unchanged from Drupal 7 - except that it's slower now. Not sure how yet but this feels like something we could optimize to more or less zero cost.

https://api.drupal.org/api/drupal/core!modules!system!system.module/func...

Proposed resolution

Remaining tasks

User interface changes

API changes

📌 Task
Status

Active

Version

10.1

Component
Asset library 

Last updated 2 days ago

No maintainer
Created by

🇬🇧United Kingdom catch

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇳🇿New Zealand danielveza Brisbane, AU

    @dawehner pointed out that #2527846: Try to get rid of Url::fromRoute() in system_js_settings_alter() looks like it has resolved these issues. Should this one be closed?

  • 🇬🇧United Kingdom catch

    I think if possible it would be good to try to understand whether we really need all of these, would mean grepping contrib js.

      $path_settings = [
        'baseUrl' => $request->getBaseUrl() . '/',
        'pathPrefix' => $pathPrefix,
        'currentPath' => $current_path,
        'currentPathIsAdmin' => $current_path_is_admin,
        'isFront' => \Drupal::service('path.matcher')->isFrontPage(),
        'currentLanguage' => \Drupal::languageManager()-                            >getCurrentLanguage(LanguageInterface::TYPE_URL)->getId(),
      ];
    
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Not sure which conclusions to draw from this.

    baseUrl has pretty much zero perf overhead and is used the most. The rest cost some performance, but also have some use. I suspect isFront is the most expensive and also has the lowest use. If that does represent the bulk of the performance cost, I'd vote to remove only that.

  • 🇬🇧United Kingdom catch

    Yeah isFront is the most suspicious for me too, although to really benefit we'll probably need to take it out of some preprocess too.

  • 🇬🇧United Kingdom catch

    I think we should remove the isFront here, we can't deprecate it - would it have to be an 11.x only change with a change record?

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    I think so?

    How do we warn/inform sites on 10.x if deprecation is impossible?

  • 🇨🇭Switzerland berdir Switzerland

    isFront only has 3 or so real usages, the others are false positives. For those 3 contrib projects we could just open an issue there. Doesn't deal with custom so, but yeah, all we can do is a change record. There might be a way to detect it, but it's JS, which we don't really support yet in our tools I think?

    That said, the performance data here is very old and I'm wondering if removing this won't just move the cost somewhere else as it's likely the first call to that function that is expensive? So we should definitely evaluate if this is a) actually still relevant and b) that removing it won't just make that cost pop up somewhere else, before we spend time on deprecations and so on.

  • 🇬🇧United Kingdom catch

    @Berdir we'd immediately see it again in template_preprocess_page() and template_preprocess_html(), but I also want to remove the is_front handling from that or do 📌 Replace template_preprocess() and possibly other things with Twig global variables/functions Active so that it's only calculated when it's actually requested.

    So yeah we'd need to remove it from at least those three places to see any improvement but I think those are the only places that absolutely 100% require it on every HTML response from Drupal.

  • 🇬🇧United Kingdom catch

    More detail on #24.

    There's two things we have to get to know if we're on the front page - the current route match, which we can't avoid doing elsewhere, so we won't save anything there.

    The other bit is (from PathMatcher):

       if (!isset($this->frontPage)) {
          $this->frontPage = $this->configFactory->get('system.site')
            ->get('page.front');
        }
    

    system.site is also used in the branding block - but that block is cacheable so it won't be getting that config every request. I don't think it's used anywhere else on every-page building by default.

    So what we'd actually save is loading the system.site config and a few function calls.

Production build 0.71.5 2024