\Drupal\Core\Asset\LibraryDiscoveryParser should use FileCache to cache the parsed YAML

Created on 15 January 2024, 12 months ago
Updated 2 February 2024, 11 months ago

Problem/Motivation

Most Yaml files are cached by FileCache so we don't have to reread them on a cache clear. See \Drupal\Component\Discovery\YamlDiscovery

This means that library YAML files have to be re-read on a cache clear even when the files do not change. This is different from info.yml, service.yml and any of the plugin yaml files.

Proposed resolution

Use the FileCache in \Drupal\Core\Asset\LibraryDiscoveryParser

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ“Œ Task
Status

Fixed

Version

11.0 πŸ”₯

Component
Asset libraryΒ  β†’

Last updated about 18 hours ago

No maintainer
Created by

πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

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

Merge Requests

Comments & Activities

  • Issue created by @alexpott
  • Merge request !6182Use file cache in library discovery β†’ (Open) created by alexpott
  • Status changed to Needs review 12 months ago
  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    I can't find anything to complain about πŸ€“

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Question, is this a feature we should add test coverage for?

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    @smustgrave I've added a test - it's not hard to add something small to a unit test for this.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    One nit on the MR.

    Should we do some profiling or benchmarking here? πŸ€” I think it's not really necessary because this only happens in the cold cache scenario, per:

    This means that library YAML files have to be re-read on a cache clear even when the files do not change. This is different from info.yml, service.yml and any of the plugin yaml files.

    … but it sure wouldn't hurt. We don't want to make the cold cache scenario more expensive/slower. But if anything, this should make it faster/cheaper.

  • πŸ‡¬πŸ‡§United Kingdom alexpott πŸ‡ͺπŸ‡ΊπŸŒ

    For the given code in test_script.php, Standard profile installed, on PHP 8.2 and APCu installed and enabled on CLI:

    
    use Drupal\Component\Utility\Timer;
    $modules = array_keys(\Drupal::getContainer()->getParameter('container.modules'));
    
    foreach($modules as $module) {
      \Drupal::service('library.discovery.parser')->buildByExtension($module);
    }
    
    
    for ($i = 0; $i < 10; $i++) {
      drupal_flush_all_caches();
      Timer::start('library.discovery.parser');
      foreach($modules as $module) {
        \Drupal::service('library.discovery.parser')->buildByExtension($module);
      }
      Timer::stop('library.discovery.parser');
    }
    
    $time = Timer::read('library.discovery.parser');
    print "Library parsing completed in {$time}ms\n";
    

    With MR using Symfony YAML

    $ vendor/bin/drush scr test_script.php
    Library parsing completed in 63.54ms
    

    Without patch using Symfony YAML

    $ vendor/bin/drush scr test_script.php
    Library parsing completed in 117.06ms
    

    Without patch and with PECL YAML installed

    $ vendor/bin/drush scr test_script.php
    Library parsing completed in 75.47ms
    
  • Status changed to RTBC 11 months ago
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Random failure in https://git.drupalcode.org/project/drupal/-/jobs/662217 because the MySQL DB went away, which made 4 unrelated kernel tests fail. I cannot retest this job πŸ€·β€β™‚οΈ

    #8 provides the numbers that remove any worries about cold cache scenarios πŸ‘

    • catch β†’ committed 92670519 on 11.x
      Issue #3414807 by alexpott, Wim Leers, smustgrave: \Drupal\Core\Asset\...
  • Status changed to Fixed 11 months ago
  • πŸ‡¬πŸ‡§United Kingdom catch

    Committed/pushed to 11.x, thanks!

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

Production build 0.71.5 2024