Adamw has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/92170


Change subject: Minor optimization to the AutoLoader
......................................................................

Minor optimization to the AutoLoader

When MediaWiki autoloading fails, we should gracefully return false.
Instead, we have been calling strtolower roughly 1,000 times in the hope
of finding a case-insensitive match.

This patch preserves the existing janky, legacy logic, but improves its
performance by approximately 100x, by storing the case-insensitive class
lookups as a static variable.

I'd rather see the case-insensitive clause go away entirely, the only
justification is a comment saying something about PHP4 serialization.

There is a new global $wgAutoloadAttemptLowercase which will switch the
behavior if desired.  The default is to leave behavior unchanged.

Change-Id: Ifb12e05614a48390b730167e9d4ddcd8545db764
---
M includes/AutoLoader.php
M includes/DefaultSettings.php
2 files changed, 25 insertions(+), 12 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/70/92170/1

diff --git a/includes/AutoLoader.php b/includes/AutoLoader.php
index 0706fe3..3bbcd9b 100644
--- a/includes/AutoLoader.php
+++ b/includes/AutoLoader.php
@@ -1145,7 +1145,8 @@
         * as well.
         */
        static function autoload( $className ) {
-               global $wgAutoloadClasses, $wgAutoloadLocalClasses;
+               global $wgAutoloadClasses, $wgAutoloadLocalClasses,
+                       $wgAutoloadAttemptLowercase;
 
                // Workaround for PHP bug 
<https://bugs.php.net/bug.php?id=49143> (5.3.2. is broken, it's
                // fixed in 5.3.6). Strip leading backslashes from class names. 
When namespaces are used,
@@ -1160,28 +1161,35 @@
                        $filename = $wgAutoloadLocalClasses[$className];
                } elseif ( isset( $wgAutoloadClasses[$className] ) ) {
                        $filename = $wgAutoloadClasses[$className];
-               } else {
+               } elseif ( $wgAutoloadAttemptLowercase ) {
                        # Try a different capitalisation
                        # The case can sometimes be wrong when unserializing 
PHP 4 objects
                        $filename = false;
                        $lowerClass = strtolower( $className );
+                       static $autoloadLocalClassesLower = null;
 
-                       foreach ( $wgAutoloadLocalClasses as $class2 => $file2 
) {
-                               if ( strtolower( $class2 ) == $lowerClass ) {
-                                       $filename = $file2;
-                               }
+                       if ( is_null( $autoloadLocalClassesLower ) ) {
+                               $autoloadLocalClassesLower = array_map( 
'strtolower', $wgAutoloadLocalClasses );
                        }
 
-                       if ( !$filename ) {
-                               if ( function_exists( 'wfDebug' ) ) {
-                                       wfDebug( "Class {$className} not found; 
skipped loading\n" );
+                       if ( isset( $autoloadLocalClassesLower[$lowerClass] ) ) 
{
+                               if ( function_exists( 'wfWarn' ) ) {
+                                       wfWarn( "Class {$className} was loaded 
using forced lowercase.\n" );
                                }
-
-                               # Give up
-                               return false;
+                               $filename = 
$autoloadLocalClassesLower[$lowerClass];
                        }
                }
 
+               if ( !$filename ) {
+                       if ( function_exists( 'wfDebug' ) ) {
+                               # FIXME: This is not very polite.  Assume we do 
not manage the class.
+                               wfDebug( "Class {$className} not found; skipped 
loading\n" );
+                       }
+
+                       # Give up
+                       return false;
+               }
+
                # Make an absolute path, this improves performance by avoiding 
some stat calls
                if ( substr( $filename, 0, 1 ) != '/' && substr( $filename, 1, 
1 ) != ':' ) {
                        global $IP;
diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php
index dbdd89e..b42081c 100644
--- a/includes/DefaultSettings.php
+++ b/includes/DefaultSettings.php
@@ -5954,6 +5954,11 @@
 $wgAutoloadClasses = array();
 
 /**
+ * Switch controlling legacy case-insensitive classloading.
+ */
+$wgAutoloadAttemptLowercase = true;
+
+/**
  * An array of extension types and inside that their names, versions, authors,
  * urls, descriptions and pointers to localized description msgs. Note that
  * the version, url, description and descriptionmsg key can be omitted.

-- 
To view, visit https://gerrit.wikimedia.org/r/92170
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ifb12e05614a48390b730167e9d4ddcd8545db764
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Adamw <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to