Download & Extend

Cache the sets of JavaScript/CSS in drupal_get_library()

Project:Drupal core
Version:7.x-dev
Component:javascript
Category:task
Priority:normal
Assigned:Unassigned
Status:closed (won't fix)
Issue tags:drupal_add_library, Libraries

Issue Summary

#315100: Allow to add JS/CSS libraries (sets of files, settings, and dependent libraries) allowed modules to register sets of JavaScript/CSS libraries. The problem is that it's not cached. This means that if a contributed module did something really expensive with the registry, like searching for libraries on the harddrive, or did a complex alterations of them, it could potentially be a big performance hit. This issue is to cache that registry so that we don't run into these performance implications.

AttachmentSizeStatusTest resultOperations
drupal.get_.library.cache_.patch5.58 KBIdleFailed: 12458 passes, 11 fails, 0 exceptionsView details | Re-test

Comments

#1

Status:needs review» needs work

On one hand, you're right that there might be a module that performs heavy actions to alter libraries. Libraries API might be a good example. On the other hand, a module like that most probably has to perform many other additional actions anyway, so it needs it separate caching (and controlled cache flushing) anyway.

+  if (isset($module)) {
+    return isset($libraries[$module][$name]) ? $libraries[$module][$name] : FALSE;
   }
   else {
-    $libraries[$module][$name] = FALSE;
+    return $libraries;
   }

Usage of $name leads to a PHP notice here.

#2

Issue tags:+Libraries

Tagging.

#3

#4

Status:postponed» needs review

Updates to HEAD, takes sun's note about the $name into account and fixes a namespace issue.

AttachmentSizeStatusTest resultOperations
510334.patch5.91 KBIdleFailed: 12766 passes, 0 fails, 30 exceptionsView details | Re-test

#5

/me subscribes

#6

Status:needs review» needs work

The last submitted patch failed testing.

#7

Status:needs work» needs review

HEAD is broken.

#8

Really expensive libraries can use own caching. We have to end the cache explosion soon. -1.

#9

Moshe, what about modules that regex a file to find out what version of the library they have? To improve the developer experience (modules wouldn't have to cache the data themselves), as well as improve performance (calling a number of module hooks which could do expensive things like regex an opened file), we could just easily cache the library array.

#10

Status:needs review» closed (won't fix)

Neither of those arguments is compelling. Adding caches rarely improves developer experience. You then have to understand what cache to clear when you are developing and debugging ... Further, the performance gain here is insignificant. It *only* could happen for an expensive operation when its module author cannot be bothered to do own caching.

This is a speculative cache. It might help under certain circumstances that are theoretical. Drupal has enough caches without implementing speculative ones.