Spin-off from #1737148: Explicitly declare all JS dependencies, don't use drupal_add_js:

Problem

  • hook_library_info() and hook_library_info_alter() is re-invoked and re-processed from scratch on every request in drupal_get_library(), although the registered information is not supposed to change.

Goal

  • Improve performance.
  • Prevent modules from registering library info that is dynamic (varies per request).

Proposed solution

  1. Cache hook_library_info() [per module].
CommentFileSizeAuthor
drupal8.library-info-cache.0.patch935 bytessun
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Assigned: Unassigned » sun

Status: Needs review » Needs work

The last submitted patch, drupal8.library-info-cache.0.patch, failed testing.

moshe weitzman’s picture

I disagree with caches for info hooks like this. If a module is doing something slow during an info hook, it should do own caching. We need proof that performance is improved with this patch. As for Prevent modules from registering library info that is dynamic (varies per request)., we don't babysit broken code, especially by adding caches. Use Doxygen and handbook for education.

pounard’s picture

moshe +1 I definitely agree, this sounds like a useless cache. I prefer to see 100 module_invoke() running than a database query; I'm quite sure the database (or any other external storage server) query will be slower.

catch’s picture

Yeah unless this is shown to be slow, and the cache()->get() to be faster, I don't see the benefit either.

sun’s picture

Seems I forgot one of the primary reasons for adding a cache here (probably because I wanted to make that a separate follow-up issue):

We need to properly resolve the dependencies between libraries. Right now:

1) The dependencies are "resolved" at runtime, but they are just simply processed in the order in which they are defined, not in the order of dependencies.

2) Nested dependencies (dependencies of dependencies) are not resolved, which means that every library has to specify all of its dependencies manually. Thus, it's very tricky to inject or remove a dependency via hook_library_alter().

3) Missing dependencies are determined at runtime only.

nod_’s picture

2) They are resolved. We explicitly define them because it should be possible from contrib to build AMD definitions from the informations in hook_library_info(), see #1737148-99: Explicitly declare all JS dependencies, don't use drupal_add_js. You can have any level of dependencies, there is recursion going on in drupal_process_attached and when you end up with circular dependencies, things break.

Wim Leers’s picture

I can confirm that point 2, nested dependencies, are indeed resolved. The Aloha module leverages this.

EDIT: and both on D7 and D8, this works.

tim.plunkett’s picture

Issue tags: +needs profiling

Fixing tags.

nod_’s picture

nod_’s picture

Status: Needs work » Closed (duplicate)
nod_’s picture

Issue summary: View changes

Updated issue summary.