Problem/Motivation

Function calls require_once so using drupal_static() and clearing this static is pointless.

On cache flush:

Before:

Total Self: 94ms
Total Cumulative: 163ms
Calls: 2,982

After:

Total Self: 49ms
Total Cumulative: 72ms
Calls: 2,982

Total savings ~90ms.

Proposed resolution

Add static cache to module_load_include()

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Profiling Instructions
Update the issue summary noting if allowed during the beta Instructions
Review patch to ensure that it fixes the issue, stays within scope, is properly documented, and follows coding standards Instructions
CommentFileSizeAuthor
#106 add_static_cache_to-1443308-106.patch843 bytescilefen
#100 Screen Shot 2015-12-17 at 12.01.52.png171.18 KBalexpott
#100 1443308-100.patch1.91 KBalexpott
#100 91-100-interdiff.txt420 bytesalexpott
#94 XHProf__Hierarchical_Profiler_Report.png216.25 KBjoelpittet
#94 XHProf__Hierarchical_Profiler_Report.png167.23 KBjoelpittet
#93 XHProf__Hierarchical_Profiler_Report.png116.43 KBjoelpittet
#92 XHProf-module_load_include.png205.31 KBjoelpittet
#92 XHProf_is_file.png202.16 KBjoelpittet
#92 XHprof__overview.png206.28 KBjoelpittet
#91 add_static_cache_to-1443308-91.patch1.84 KBcilefen
#91 interdiff-86-91.txt1.83 KBcilefen
#90 interdiff-80-86.txt481 bytescilefen
#86 add_static_cache_to-1443308-86.patch2.24 KBstewsnooze
#81 add_static_cache_to-1443308-80.patch2.47 KBcilefen
#80 add_static_cache_to-1443308-80.patch0 bytescilefen
#80 interdiff.txt1.52 KBcilefen
#76 add_static_cache_to-1443308-76.patch2.58 KBcilefen
#76 interdiff.txt1.5 KBcilefen
#69 drupal8-1443308-69-module_load_include-static-cache.patch2.25 KBjonhattan
#64 drupal8-1443308-64-module_load_include-static-cache.patch1.7 KBjoseph.olstad
#62 drupal8-1443308-62-module_load_include-static-cache.patch1.65 KBjoseph.olstad
#60 drupal8-1443308-60-module_load_include-static-cache.patch821 bytesjoseph.olstad
#57 drupal8-1443308-56-module_load_include-static-cache.patch1.68 KBjoseph.olstad
#49 drupal-1443308-49-module_load_include-static-cache.patch838 bytesmarcingy
#39 cc-all-pre-patch.jpg25.02 KBbtopro
#39 cc-all-post-patch.jpg36.46 KBbtopro
#37 drupal-1443308-37-module_load_include-static-cache.patch839 bytesbtopro
#22 add_static_cache_to-1443308-22-d8.patch832 bytesjoelpittet
#20 Xhgui_-_Symbol_-_module_load_include_and_Xhgui_-_Symbol_-_module_load_include.png185.72 KBjoelpittet
#9 drupal-1443308-9-module_load_include-static-cache.patch839 bytesmikeytown2
#1 drupal-1443308-1-add-static-cache-to-module_load_include.patch854 bytesmikeytown2
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mikeytown2’s picture

Status: Active » Needs review
FileSize
854 bytes
mikeytown2’s picture

Non Cache Flush:
Before:
Total Self: 21ms
Total Cumulative: 27ms
Calls: 312

After:
Total Self: 15ms
Total Cumulative: 16ms
Calls: 311

total savings ~10ms

mgifford’s picture

PlayfulWolf’s picture

No testing results for a month??

mikeytown2’s picture

patch is still green in #1 so it passed all tests.

PlayfulWolf’s picture

So, there are plans to apply it to next release or you need more testers?

mikeytown2’s picture

This is core so I have no control over if and when this goes in. The first step would be for the status to change from needs review to reviewed & tested by the community. That requires people saying that this patch works. So far I'm the only one who has stated that.

tstoeckler’s picture

Can you explain what this patch does, I don't get it. Thx.

mikeytown2’s picture

Great question as the patch in #1 was missing an important bit of code. Also looks like on my test environment this doesn't show any sort of improvement as before... So this patch is useful if you have code stored on a slow drive like NFS. We recently switched code off of NFS so we don't see the improvements now. Oh well...

On cache flush:
module_load_include()

Before:
Total Self: 43ms
Total Cumulative: 85ms
Calls: 1,702

After:
Total Self: 45ms
Total Cumulative: 84ms
Calls: 1,995

Total savings ~1ms.

drupal_get_path()

Before:
Total Self: 40ms
Total Cumulative: 55ms
Calls: 3,015

After:
Total Self: 39ms
Total Cumulative: 54ms
Calls: 2,925

Total savings ~1ms.

is_file()
Before:
Calls: 1,712

After:
Calls: 1,612

Total savings ~100 less calls to built in PHP function is_file.

Conclusion: Unless your code is stored on a slow drive, this patch is pointless.

PlayfulWolf’s picture

In general, the share is growing of hosting environments where the VPS/user VMs are on relatively light and inexpensive servers and files are on SAN/NAS/dedicated *raid storage machines, so this patch still makes sense, right?

p.s. I am just curious, because found link to this patch in many discussions, where drupal is running slow because of quantity of files and similar stuff.

tstoeckler’s picture

Version: 7.x-dev » 8.x-dev
Issue tags: +Needs backport to D6, +Needs backport to D7

Well, if we can prove that this improves performance on some environments without hurting it (noticably) on others, that would be a strong case to get this in. Especially if those environments are shared hosters, which Drupal generally does not perform well for.

I'm pretty sure this applies to Drupal 8 as well, and hence should go there first, but could be backported all the way to Drupal 6. Adding tags accordingly.

tstoeckler’s picture

Issue summary: View changes

Updated issue summary.

mgifford’s picture

Status: Needs review » Needs work

The last submitted patch, 9: drupal-1443308-9-module_load_include-static-cache.patch, failed testing.

The last submitted patch, 9: drupal-1443308-9-module_load_include-static-cache.patch, failed testing.

mikeytown2’s picture

Version: 8.x-dev » 7.x-dev
Component: browser system » file system
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs backport to D7 +needs forwardport to D8

Updating tags to show that the patch in #9 is for D7. Will retest patch as D7 and then once this passes we can move the issue back to D8.

mikeytown2’s picture

mikeytown2’s picture

Version: 7.x-dev » 8.x-dev

Patch passes. Moving issue back to D8

Status: Needs review » Needs work

The last submitted patch, 9: drupal-1443308-9-module_load_include-static-cache.patch, failed testing.

joelpittet’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
185.72 KB

Re D7 #9 Commerce Views listing page on a site that has ~375 enabled modules.

I love this module it saves > 1sec load time on cold caches after registry rebuild.

joelpittet’s picture

+++ b/includes/module.inc
@@ -320,17 +320,24 @@ function module_load_install($module) {
+  $key = $type . ':' . $module . ':' . $name;

Do we need to deal with $name = NULL? xmlsitemap module has an example of this use case.

joelpittet’s picture

Here's the patch for D8.

joelpittet’s picture

Issue tags: -needs forwardport to D8 +Needs backport to D7
joelpittet’s picture

mikeytown2’s picture

RE #21: NULL should be cast to an empty string
http://php.net/types.type-juggling#24809

joelpittet’s picture

@mikeytown2 I know that much, I guess my question was too generic there, sorry.

I was just wondering if there would be any cache collisions with 'type:module:'?

mikeytown2’s picture

Fairly certain there would not be a cache collision.

joelpittet’s picture

I think so too, thought I'd ask. Let's see if we can get this into D8/7/6:)

penyaskito’s picture

I would suggest using module if name is empty (from docblock: If omitted, $module is used). This way we hide the implementation detail AND increase the hit rate if we have code that explicits name=module and name=NULL.

joelpittet’s picture

+++ b/core/includes/module.inc
@@ -137,17 +137,24 @@ function module_load_install($module) {
+  static $file_name = array();
   if (!isset($name)) {
     $name = $module;
   }
+  $key = $type . ':' . $module . ':' . $name;

@penyaskito we have a check for !isset($name), I'd rather not change functionality to empty() as it could be disruptive, no?

YesCT’s picture

Issue summary: View changes
Issue tags: +Need issue summary update

normal feature request is a red flag.
Needs a beta evaluation. instructions are in the summary.

penyaskito’s picture

@joelpittet Oops, I miss-looked at it, the key never will look like 'type:module:', so IMHO there is nothing wrong on the last patch.

Fabianx’s picture

Category: Feature request » Task

Thanks, YesCT, this is mis-categorized.

Uhm, that is a task, not a feature request.

Depending if you can show that it saves much, it can even be major.

mikeytown2’s picture

@Fabianx
#20. Mainly helpful if the code is on a slower disk (NFS, Virtual, etc). There is minimal downside to this from what I can see. My original tests were with apc.stat=0 so that can be ruled out as a possible solution.

jhedstrom’s picture

It would be helpful if somebody could re-run the benchmarks listed in the issue summary on current D8.

With this change, would it also make sense to use require instead of require_once?

pendashteh’s picture

Issue tags: -Need issue summary update +Needs issue summary update

Correcting miss-spelled tag.

btopro’s picture

Status: Needs review » Needs work

The last submitted patch, 37: drupal-1443308-37-module_load_include-static-cache.patch, failed testing.

btopro’s picture

FileSize
36.46 KB
25.02 KB

Tested before and after cache clear on a pretty complicated site (154 modules, decent caching mechanisms in place, php / mysql 5.5 / opcache). This is running on a Local CentOS 6.5 Vagrant instance.

Prior to patch


4103

After patch


2394

btopro’s picture

Version: 8.0.x-dev » 7.x-dev

switching to 7.x temporarily to allow test bot to pick it up correctly

btopro’s picture

Version: 7.x-dev » 8.0.x-dev

back to 8 since that's where thread was but the patch I rerolled for #37 passed tests

Fabianx’s picture

Status: Needs work » Reviewed & tested by the community

Uhm, RTBC? Looks pretty straightforward to me.

penyaskito’s picture

#35 is still unanswered. Could we use require instead of require_once? What is the gain?

btopro’s picture

performance difference between the two should be nominal on anything running opcache (5ms otherwise maybe, pushing it to suggest that high even)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 37: drupal-1443308-37-module_load_include-static-cache.patch, failed testing.

marcingy’s picture

Just looking through this patch and any reason why it does

if (!empty($file_name[$key])) {
   return $file_name[$key];
}

Instead of

if (isset($file_name[$key])) {
  return $file_name[$key];
}

As currently this will attempt to load multi times when a file is missing.

marcingy’s picture

Fabianx’s picture

Status: Needs work » Reviewed & tested by the community

Back to RTBC - Should profile this again with DB in IS.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 49: drupal-1443308-49-module_load_include-static-cache.patch, failed testing.

The last submitted patch, 49: drupal-1443308-49-module_load_include-static-cache.patch, failed testing.

mgifford’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Needs work » Needs review

This has to be for the D7 version.

mikeytown2’s picture

Status: Needs review » Reviewed & tested by the community

Should actually be RTBC

David_Rothstein’s picture

Version: 7.x-dev » 8.0.x-dev
Status: Reviewed & tested by the community » Needs work

This looks interesting, but still needs to go into Drupal 8 first.

Just for fun, it looks like Drupal 8 has two functions that do a similar thing, module_load_include() itself plus ModuleHandler::loadInclude(). Perhaps the static cache would be useful on both.

joseph.olstad’s picture

joseph.olstad’s picture

Status: Needs work » Needs review

I have no idea if this will pass or not, I didn't test it but looks simple enough.

Status: Needs review » Needs work

The last submitted patch, 57: drupal8-1443308-56-module_load_include-static-cache.patch, failed testing.

joseph.olstad’s picture

ok, start simple this time.

joseph.olstad’s picture

Status: Needs work » Needs review
joseph.olstad’s picture

Ok, patch 60 passed, now try this one just for fun.
*EDIT* I cancelled tests for this patch and then wrote a new patch #64

Status: Needs review » Needs work

The last submitted patch, 62: drupal8-1443308-62-module_load_include-static-cache.patch, failed testing.

joseph.olstad’s picture

Status: Needs work » Needs review
FileSize
1.7 KB

I'd do an interdiff, but it's not that big.

basically patch 62 and 56 missing key value on loadInclude, putting that in, should get better test results

Fabianx’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update +rc target triage

Don't think we can test this ...

Edit: The patch is RTBC. I don't think there is a way to test an internal static, therefore I am marking as RTBC and also rc target triage so it is considered for the RC phase.

joseph.olstad’s picture

@Fabianx, I am confused by your comment #65

cilefen’s picture

  1. +++ b/core/includes/module.inc
    @@ -126,17 +126,24 @@ function module_load_install($module) {
     function module_load_include($type, $module, $name = NULL) {
    +  static $file_name = [];
       if (!isset($name)) {
    

    Wouldn't it make more sense to call this $file_names?

  2. +++ b/core/includes/module.inc
    @@ -126,17 +126,24 @@ function module_load_install($module) {
    +  $key = $type . ':' . $module . ':' . $name;
    +  if (!isset($file_name)) {
    +    return $file_name[$key];
    +  }
    

    I don't understand how this works. If the static cache is not set, we return the file name without checking if it exists. What would be returned in this case?

cilefen’s picture

Status: Reviewed & tested by the community » Needs work
jonhattan’s picture

Component: file system » extension system
Status: Needs work » Needs review
FileSize
2.25 KB

Changes:

* Use $files as the static variable name instead of $file_name
* Fixes #67.2 - the logic implemented in module_load_include() is wrong
* Reorder the code to use only a return statement

cilefen’s picture

@jonhattan Nice!

Fabianx’s picture

Status: Needs review » Needs work
+++ b/core/includes/module.inc
@@ -126,18 +126,25 @@ function module_load_install($module) {
+    $files[$key] = FALSE;
+    if (function_exists('drupal_get_path')) {

This is wrong, we should not say a file does not exist, when the drupal_get_path function is not (yet) in scope. We should ignore the static cache in that case.

I think adding it in an else {} block should be fine though as it is unlikely that drupal_get_path result changes within the same request.

However the safer version is to only populate the cache when an item is found.

cilefen’s picture

Is there a reason we are not using drupal_static()?

Fabianx’s picture

#72: Yes, IS states so:

files can only be added not removed during a run, so there is no need to ever clear the static - as the function calls require_once.

cilefen’s picture

Issue summary: View changes
catch’s picture

ModuleHandler can use a class property, doesn't need to be an actual static.

cilefen’s picture

Status: Needs work » Needs review
FileSize
1.5 KB
2.58 KB

This is the recommendation in #75. #71 still needs doing.

xjm’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

Thanks for tagging this for rc target triage! If you want committers to consider it for inclusion in RC, add a statement to the issue summary of why we need to make this change during RC, including what happens if we do not make the change and what any disruptions from it are. You can add a section <h3>Why this should be an RC target</h3> to the summary.

cilefen’s picture

@Fabianx Re #71: How do we resolve the path the file reliably without drupal_get_path()?

Fabianx’s picture

#78: What I mean is:

We do _never ever_ want to cache the result when drupal_get_path function is not available as that will always be wrong.

cilefen’s picture

Status: Needs work » Needs review
FileSize
1.52 KB
0 bytes
cilefen’s picture

The last submitted patch, 80: add_static_cache_to-1443308-80.patch, failed testing.

Fabianx’s picture

Looks great now - RTBC - except for nit, still needs profiling and IS update:

+++ b/core/lib/Drupal/Core/Extension/ModuleHandler.php
@@ -257,20 +264,24 @@ public function loadAllIncludes($type, $name = NULL) {
+

superfluous - space

Status: Needs review » Needs work

The last submitted patch, 81: add_static_cache_to-1443308-80.patch, failed testing.

The last submitted patch, 81: add_static_cache_to-1443308-80.patch, failed testing.

stewsnooze’s picture

Fixed the tiny whitespace niggle that Fabianx mentioned in #83

cilefen’s picture

Status: Needs work » Needs review

The last submitted patch, 81: add_static_cache_to-1443308-80.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 86: add_static_cache_to-1443308-86.patch, failed testing.

cilefen’s picture

FileSize
481 bytes
joelpittet’s picture

I forgot how amazing this was for D7 and lost this patch. Reapplied #9 and wanted to share:
The scenario is a cart page with cache primed.



I'll see what I can do about getting some profiling results on D8 site.

joelpittet’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
Issue tags: -needs profiling
FileSize
116.43 KB

Of course I don't have as many modules enabled in D8 as I did in D7 so the gain is not as amazing.

Scenario: I turned page/dynamic page caching off, enabled all the core modules + xhprof + devel modules and rebuilt the registry and hit /admin/modules

The function doesn't get called as many times compared to the other but the time % diff is still nice:)

15% wall time improvement with a 7.5% memory regression seems to be a good trade off to me:

joelpittet’s picture

Issue summary: View changes
Issue tags: -rc target triage, -Needs issue summary update
FileSize
167.23 KB
216.25 KB

Here's an is_file() diff for the same scenario except there were more calls on the admin/content page from what looks like views.

catch’s picture

It looks like something else is wrong that we're checking the existence of views.views_execution.inc 164 times on admin/content - do you know what's causing that? Are we really doing that for 164 different views hooks or something?

joelpittet’s picture

@catch I think you mis-read that picture. is_file() is called 164 times diff. views.views_execution.inc has 0 diff. Those are only ever checked once.

alexpott’s picture

We checking for the existence of MODULE.views_execution.inc for every installed module multiple times because we fire these...

  1. \Drupal::moduleHandler()->invokeAll('views_pre_view', array($this, $display_id, &$this->args));
  2. $module_handler->invokeAll('views_pre_build', array($this));
  3. \Drupal::moduleHandler()->invokeAll('views_query_alter', array($view, $this));
  4. $query->addMetaData('views_substitutions', \Drupal::moduleHandler()->invokeAll('views_query_substitutions', array($this->view)));
  5. $module_handler->invokeAll('views_post_build', array($this));
  6. $module_handler->invokeAll('views_pre_execute', array($this));
  7. $module_handler->invokeAll('views_post_execute', array($this));
  8. $module_handler->invokeAll('views_pre_render', array($this));
  9. $module_handler->invokeAll('views_post_render', array($this, &$this->display_handler->output, $cache));
  10. $substitutions = \Drupal::moduleHandler()->invokeAll('views_form_substitutions');

We also try to load MODULE.views.inc for every installed module multiple times because of the alter $this->moduleHandler->alter($this->alterHook, $definitions); where the alter hooks are

  1. views_plugins_field
  2. views_plugins_filter
  3. views_plugins_relationship
  4. views_plugins_area
  5. views_plugins_exposed_form
  6. views_plugins_query
  7. views_plugins_pager
  8. views_plugins_join
  9. views_plugins_cache

So for every module installed once views is installed you get 17 unnecessary is_file() checks on a cache rebuild.

catch’s picture

Yes sorry #95 should've said MODULE.views_extension.inc, thanks for right answers to my wrong question.

This is another reason to get rid of hook_hook_info() per #2233261: Deprecate hook_hook_info() although that's 9.x material unfortunately.

In the meantime we ought to be able to check the file existence once per hook group per module per request, if we do that, I don't see what the static cache gets us in 8.x and would be tempted to move this directly to 7.x. Not changing status just yet though.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I think given how ModuleHandler::buildImplementationInfo() works the current solution to add static caching to ModuleHandler::loadInclude() might be the simplest. I'm not sure we should change module_load_include() - in fact I think we should open an issue to deprecate the function for 9.x and replace all of the usages in core where possible - the only place where it is not possible is the installer and for that we could just copy&rename the function and put it in install.core.inc.

Also we should store the results when is_file() returns FALSE - this way we would get 731 less calls to is_file() on admin/content as opposed to 165.

alexpott’s picture

Status: Needs work » Needs review
FileSize
420 bytes
1.91 KB
171.18 KB

Here's a patch that stores the FALSE results of is_file()

The difference on a cache rebuild on admin/content:

alexpott’s picture

The other advantage of caching the FALSE results of is_file() is that PHP doesn't cache information about non-existent files so funnily enough this is probably saving more disk access than the patch in #91.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

Setting back to RTBC, thanks @alexpott nice extra touch.

joelpittet’s picture

  • catch committed b2bb8d3 on 8.1.x
    Issue #1443308 by cilefen, joseph.olstad, mikeytown2, joelpittet, btopro...
catch’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

I've committed/pushed this to 8.1.x, without the module_load_include() hunk though since that doesn't seem relevant to 8.x if we cache the not-found files, and if we convert usages away and deprecate it too.

Moving to 7.x for backport, I don't think this is worth an 8.0.x backport (we'd have to deal with @internal-izing the protected property) - but if someone strongly feels it should go into 8.0.x then feel free to set to that version.

cilefen’s picture

Status: Patch (to be ported) » Needs review
FileSize
843 bytes
tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs backport to D7

If it's good enough for D8, I guess it's good enough for D7 too. I verified that the code matches.

pounard’s picture

For Drupal 7, there is a possible variant without static cache, which is half slower when xdebug is enabled, but in par with static cache with opcache and without xdebug (did a few local benchmarks involving including something like 400 PHP files 10000 times):

function module_load_include($type, $module, $name = NULL) {
  if (!isset($name)) {
    $name = $module;
  }

  if (function_exists('drupal_get_path')) {
    $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
    if (@include_once $file) {
      return $file;
    }
  }
  return FALSE;
}
alexpott’s picture

@pounard what happens if the included file has a PHP error in? I think this would a change of behaviour.

pounard’s picture

That's an excellent question, I think that this would mask the warnings only if the code executes directly PHP code, or potentially mask fatal parsing errors (although I'm not sure about those) but it won't otherwise; but it needs maybe some more research or testing about this.

catch’s picture

Status: Reviewed & tested by the community » Needs review

Back to needs review for choosing either option.

pounard’s picture

@alexpott's was a good one, and I think using the @ operator would indeed mask PHP errors when parsing the loaded files, I think it's a dangerous behaviour change. I'm sad we cannot get rid of all the is_file() calls but I don't see a better alternative than the static cache right now.

jonhattan’s picture

Status: Needs review » Reviewed & tested by the community

Indeed @ operator silences errors when the included file has any syntax error. Back to RTBC

pounard’s picture

Status: Reviewed & tested by the community » Needs work

Not exactly, the static cache should only be populated if the drupal_get_path() function exists: in case a file load attempt is done before Drupal is fully bootstrapped, it won't be able to load it once it is fully bootstrapped: so this must be changed in order to ensure that it can.

 function module_load_include($type, $module, $name = NULL) {
  static $files = array();

   if (!isset($name)) {
     $name = $module;
   }
 
  $key = $type . ':' . $module . ':' . $name;
  if (isset($files[$key])) {
    return $files[$key];
  }

   if (function_exists('drupal_get_path')) {
     $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
     if (is_file($file)) {
       require_once $file;
      $files[$key] = $file;
       return $file;
     }
    else {
      $files[$key] = FALSE;
    }
   }
   return FALSE;
 }

should become:

 function module_load_include($type, $module, $name = NULL) {
  static $files = array();

  if (!function_exists('drupal_get_path')) {
    return FALSE;
  }

  if (!isset($name)) {
    $name = $module;
  }

  $key = $type . ':' . $module . ':' . $name;
  if (isset($files[$key])) {
    return $files[$key];
  }

  $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type";
  if (is_file($file)) {
    require_once $file;
    $files[$key] = $file;
    return $file;
  }
  else {
    $files[$key] = FALSE;
  }
  return FALSE;
}
jonhattan’s picture

Status: Needs work » Reviewed & tested by the community

#106 doesn't populate the cache when drupal_get_path() is not available.

pounard’s picture

Oh yeah right, I misread, I don't know how I could miss that.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: +7.42 release notes

Statically caching the FALSE results gives me some pause, since it's certainly possible to download code and load/run it all in the same page request.... But I think in practice this isn't likely to be a problem, and it's essentially the direction we're headed in #1081266: Avoid re-scanning module directory when a filename or a module is missing anyway.

Committed to 7.x - thanks!

This issue has the "needs backport to D6" tag, but I'm guessing that's not happening at this point. Feel free to reopen for Drupal 6 if you want to try :)

  • David_Rothstein committed f0d5910 on 7.x
    Issue #1443308 by cilefen, joseph.olstad, mikeytown2, joelpittet, btopro...
ndobromirov’s picture

Just a thought,

As we are keeping a static cache now and we can not include a file more than once, why are we still using the require_once instead of require only.

This comes from an old project that had to use Drupal through an NFS mount. And there were this kinds of issues:
https://bugs.php.net/bug.php?id=52312
https://echo.co/blog/speed-php-nfs-turborealpath

We can open this in a follow-up, as it's pretty straight forward.

BR,
Nikolay Dobromirov.

tstoeckler’s picture

@ndobromirov: I think that's a great idea! Can you open a follow-up? Then we could discuss that change properly. Thanks!

pjcdawkins’s picture

@ndobromirov changing from require_once() sounds problematic. The file might already have been require()d by other code (it's often a good idea but it's by no means compulsory to use module_load_include()).

pounard’s picture

I agree with #121, it does not sounds very wise to switch to require.

ndobromirov’s picture

The follow-up is here: https://www.drupal.org/node/2663228
There is a POC patch to see whether this will pass D7 core tests.
@pjcdawkins I did not consider this (#121) but it's a valid point. We will see what the test bot will say :).

pounard’s picture

follow-up or not, modules might require files by themselves, even if core passes tests, a lot of module may not.

FluxSauce’s picture

Just wanted to say thank you.

Status: Fixed » Closed (fixed)

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