Page MenuHomePhabricator

Audit and simplify MediaWiki initialisation code (Spring 2018)
Open, NormalPublic

Description

This is a tracking task for various miscellaneous tasks relating to MediaWiki PHP set-up code. It will be resolved when the sub tasks added during Spring 2018, are resolved.

Goals:

  • Reduce maintenance overhead by addressing Technical-Debt.
  • Make the code easier to contribute to by simplifying it and improving its documentation.
  • Improve startup performance, especially for stateless requests (api.php, load.php) and read-only routes.

Sub tasks:

  • Understand current initialisation logic.
  • Understand current initialisation requirements.
  • Understand current initialisation performance. – T233886#5532734
  • Improve and simplify initialisation performance in a way that continues to satisfy current requirements.

Current code (Feb 2018)

From: /w/{entrypoint}.php:

  • include PHPVersionCheck
    • PHPVersionCheck::checkRequiredPHPVersion()
    • PHPVersionCheck::checkVendorExistence()
    • PHPVersionCheck::checkExtensionExistence()
  • include WebStart
    1. WebStart: assert php-env mbstring.func_overload
    2. WebStart: emit header X-Content-Type-Options: nosniff
    3. WebStart: global set $wgRequestTime
    4. WebStart: global unset $IP
    5. WebStart: define MEDIAWIKI
    6. WebStart: global set $IP
    7. WebStart: include Setup
      1. Setup: global set $wgProfiler
      2. Setup: include StartProfiler (conditional)
      3. Setup: include AutoLoader
      4. Setup: include Defines
      5. Setup: include DefaultSettings
      6. Setup: include GlobalFunctions
      7. Setup: include vendor/autoload (conditional)
      8. Setup: assert vendor
      9. Setup: php-env add HeaderCallback
      10. Setup: include LocalSettings
    8. WebStart: include OutputHandler (conditional)
    9. WebStart: register ob_start wfOutputHandler (conditional)
      1. OutputHandler: handle ValidateAllHtml (conditional)
      2. OutputHandler: handle compression (conditional)
      3. OutputHandler: emit header Content-Length (conditional)
    10. WebStart: include Setup [continued]
      1. Setup: process Profiler (implicit)
      2. Setup: process ExtensionRegistry
      3. Setup: php-env ensure mb_internal_encoding( .. )
      4. Setup: php-env ensure LC_ALL=..
      5. Setup: process mw-config phase1/2 (DefaultSettings, LocalSettings, shortcuts, derivatives, deprecations, normalising)
      6. Setup: process MWDebug
      7. Setup: process MediaWikiServices
      8. Setup: define MW_SERVICE_BOOTSTRAP_COMPLETE
      9. Setup: php-env add MWExceptionHandler
      10. Setup: include UtfNormalUtil
      11. Setup: Setup: assert validity of $wgArticlePath
      12. Setup: process mw-config phase2/2 (more defaults, shortcuts, normalising)
      13. Setup: php-env ensure wfMemoryLimit
      14. Setup: process singletons phase1/3 (wgMemc, messageMemc, parserMemc)
      15. Setup: process hooks for SetupAfterCache
      16. Setup: process singletons phase2/3 (wgContLang, wgAuth)
      17. Setup: php-env add MediaWiki\Session
      18. Setup: process singletons phase3/3 (wgUser, wgLang, wgOut, wgParser, wgTitle)
      19. Setup: process hooks for wgExtensionFunctions
      20. Setup: process Pingback
Issues

1: WebStart: assert php-env mbstring.func_overload

Unsure why this is in WebStart instead of Setup. Is it fine to apply this to CLI?

3: WebStart: global set $wgRequestTime

Deprecated since MediaWiki 1.25.

4: WebStart: global unset $IP

This sanity unset() seems redundant. It's unconditionally re-assigned two lines down. Can it be removed?

7A: Setup: global set $wgProfiler
7B: Setup: include StartProfiler (conditional)

Seems like this could be folded into DefaultSettings.php, with the StartProfiler include moved down a few lines. Should be safe given we don't reference it after DefaultSettings and LocalSettings load.

8: WebStart: include OutputHandler (conditional)

This (conditionally) includes a file that creates additional global functions. Should be safe to merge with GlobalFunctions and just load always. Alternatively, given this is after the autoloader, perhaps better as a class. That way also has the benefit of 1) keeping the private functions really private and 2) still only loading the file when needed.

9A: OutputHandler: handle ValidateAllHtml (conditional)

See also T191670.

10A: Setup: process Profiler

10J: Setup: include UtfNormalUtil

Removed in https://gerrit.wikimedia.org/r/435207 / 88ea69f2f7.

10K: Setup: assert validity of $wgArticlePath

10L: Setup: process mw-config phase2 (more defaults, shortcuts, normalising)

Unsure why this is separate from the earlier "mw-config process" section.

  • Patch: TODO

Misc ideas and themes

(Early draft with ideas for different directions we could take.)

  • Reduce number of manually included files.
  • Reduce amount of commonly executed code:
    • Re-evaluate the way we normalise global configuration variables in Setup.php. We currently do it unconditionally because we want convenient access to them without needing to re-normalise at each call site. However, we are actively reducing use of global variables, typically using them (or the Config proxy) only in ServiceWiring.php and/or the constructor of a service class. Such class seems like a better place to perform normalisation than Setup.php. Benefits of doing so:
      1. Still written and run from one place (just in the relevant class instead of Setup.php)
      2. No longer unconditional on all requests.
      3. Testable - the code for supporting older configuration formats can be covered with unit tests.
      4. Maintained in context of the associated feature.
    • Continue deprecating (some) global functions in favour auto-loaded class methods.
    • Maybe start deprecating some constants in favour of auto-loaded class constants.

Details

Related Gerrit Patches:
mediawiki/core : mastercontext: Use getRawVal instead of getVal for 'uselang' and 'useskin'
mediawiki/core : masterSetup: Move wgArticlePath validation to its main consumer (PathRouter)
mediawiki/core : masterSetup: Remove debug message for "caches"
mediawiki/extensions/SpamBlacklist : masterMigrate HTTP cache from messageMemc to APC
mediawiki/extensions/TitleBlacklist : masterMigrate HTTP cache from messageMemc to APC
mediawiki/core : masterSetup: Move wgActionPath logic to PathRouter
mediawiki/core : masterSetup: Move MWDebug logic to MWDebug.php
mediawiki/core : masterbuild: Update wikimedia/ip-set from 2.0.1 to 2.1.0
mediawiki/core : masterWebRequest: Optimise WebRequest::getPathInfo()
mediawiki/core : masterProxyLookup: Optimise in_array in isConfiguredProxy()
mediawiki/extensions/GlobalUsage : masterAvoid usage of deprecated $wgContLang global (dep in 1.32)
mediawiki/core : masterphpunit: Don't bother resetting unused global in UploadFromUrlTestSuite
operations/mediawiki-config : masterAvoid localised url computation for P3P headers from CentralAuth
mediawiki/core : masterWebStart: Avoid DB or uselang for nonwrite-api-promise-error message
mediawiki/core : masterSetup: Remove scopedProfileIn() calls
mediawiki/core : masterSetup: Move wgRCLinkDays logic from Setup to ChangesListSpecialPage
mediawiki/extensions/Flow : masterFlowHooks: Simplify registerExtension() code a bit
mediawiki/core : masterSetup: Remove $wgDebugPrintHttpHeaders option
mediawiki/core : masterSetup: Make wfMemoryLimit() internal and simplify
mediawiki/core : masterSetup: Move mb_internal_encoding() call earlier
mediawiki/core : masterRemove deprecated wgEnableParserCache
mediawiki/core : masterPHPVersionCheck: Remove obsolete load.php code and simplify
operations/mediawiki-config : mastermultiversion: Remove reference to deprecated getRealmSpecificFilename()
mediawiki/core : masteruser: Remove use of Message:text() from User::isUsableName()
mediawiki/extensions/Wikibase : masterUse native require_once instead of manual checks and throws
operations/mediawiki-config : masterprofiler: Move vendor/autoload from MWMultiVersion to profiler.php
mediawiki/core : masterRemove support for StartProfiler.php
operations/mediawiki-config : masterRemove unused $tmarray variables
mediawiki/core : masterSetup: Remove various Profile sections
mediawiki/core : masterSetup: Move mbstring.func_overload from WebStart to Setup
mediawiki/core : masterWebStart: Remove deprecated $wgRequestTime
mediawiki/core : REL1_31WebStart: Remove redundant unset() for $IP
mediawiki/core : masterWebStart: Remove redundant unset() for $IP
mediawiki/core : masterSetup: Deprecate StartProfiler, move default to DefaultSettings
mediawiki/core : masterConvert OutputHandler functions to a class

Related Objects

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
Krinkle removed Krinkle as the assignee of this task.Dec 9 2018, 10:29 PM

Un-assigning for now as this isn't current quarter's goal. Current quarter has T202154 as my optimisation theme.

Change 486713 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Remove deprecated wgEnableParserCache

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

Change 486713 merged by jenkins-bot:
[mediawiki/core@master] Remove deprecated wgEnableParserCache

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

Krinkle updated the task description. (Show Details)Jul 13 2019, 12:35 AM

Mark removal of "10J: Setup: include UtfNormalUtil", as was done in https://gerrit.wikimedia.org/r/435207 / 88ea69f2f7.

Krinkle updated the task description. (Show Details)Jul 13 2019, 12:36 AM

Change 522578 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Move mb_internal_encoding() call earlier

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

Change 522579 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Make wfMemoryLimit() internal and simplify

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

Change 522580 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Remove $wgDebugPrintHttpHeaders option

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

Krinkle updated the task description. (Show Details)Jul 13 2019, 1:13 AM

Change 522578 merged by jenkins-bot:
[mediawiki/core@master] Setup: Move mb_internal_encoding() call earlier

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

Change 522579 merged by jenkins-bot:
[mediawiki/core@master] Setup: Make wfMemoryLimit() internal and simplify

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

Change 522580 merged by jenkins-bot:
[mediawiki/core@master] Setup: Remove $wgDebugPrintHttpHeaders option

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

Change 524537 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/extensions/Flow@master] FlowHooks: Simplify registerExtension() code a bit

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

Change 524537 merged by jenkins-bot:
[mediawiki/extensions/Flow@master] FlowHooks: Simplify registerExtension() code a bit

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

Change 526274 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] context: Use getRawVal instead of getVal for 'uselang' and 'useskin'

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

Would like CR for the above optimisation. Loosely relates to general MediaWiki initialisation perf work, motivated by upcoming REST entry point.

Change 526274 merged by jenkins-bot:
[mediawiki/core@master] context: Use getRawVal instead of getVal for 'uselang' and 'useskin'

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

Change 532263 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] WebStart: Avoid DB or uselang for nonwrite-api-promise-error message

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

Change 532264 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Remove scopedProfileIn() calls

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

Krinkle updated the task description. (Show Details)Aug 25 2019, 6:50 PM

Within the SessionManager::getGlobalSession call from Setup.php, there is also non-trivial amount of time spent in generating the P3P header for IE6-10, from CentralAuth:

Change 532268 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[operations/mediawiki-config@master] Avoid localised url computation for P3P headers from CentralAuth

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

Change 532281 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Move wgRCLinkDays logic from Setup to ChangesListSpecialPage

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

Change 532281 merged by jenkins-bot:
[mediawiki/core@master] Setup: Move wgRCLinkDays logic from Setup to ChangesListSpecialPage

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

Change 532264 merged by jenkins-bot:
[mediawiki/core@master] Setup: Remove scopedProfileIn() calls

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

Change 532263 merged by jenkins-bot:
[mediawiki/core@master] WebStart: Avoid DB or uselang for nonwrite-api-promise-error message

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

Change 532268 merged by jenkins-bot:
[operations/mediawiki-config@master] Avoid localised url computation for P3P headers from CentralAuth

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

Krinkle updated the task description. (Show Details)Aug 31 2019, 1:34 PM

Looking at an XHGui profile, I notice wfGetMessageCacheStorage is called on all PHP processes in Setup.php. Would be nice if we could get rid of that as well, by removing messageMemc. That's quite an old variable. It predates WANObjectCache as well.

Change 533696 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] phpunit: Don't bother resetting unused global in UploadFromUrlTestSuite

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

Change 533698 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/extensions/TitleBlacklist@master] Migrate HTTP cache from messageMemc to APC

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

Change 533699 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/extensions/SpamBlacklist@master] Migrate HTTP cache from messageMemc to APC

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

Change 533701 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Remove debug message for "caches"

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

Change 533701 merged by jenkins-bot:
[mediawiki/core@master] Setup: Remove debug message for "caches"

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

Change 533696 merged by jenkins-bot:
[mediawiki/core@master] phpunit: Don't bother resetting unused global in UploadFromUrlTestSuite

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

Change 533716 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] ProxyLookup: Optimise in_array in isConfiguredProxy()

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

Change 533720 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Move wgActionPath logic to PathRouter

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

Change 533723 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Move MWDebug logic to MWDebug.php

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

Change 533773 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] WebRequest: Optimise WebRequest::getPathInfo()

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

Change 533869 had a related patch set uploaded (by Krinkle; owner: Derick Alangi):
[mediawiki/extensions/GlobalUsage@master] Avoid usage of deprecated $wgContLang global (dep in 1.32)

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

Change 533869 merged by jenkins-bot:
[mediawiki/extensions/GlobalUsage@master] Avoid usage of deprecated $wgContLang global (dep in 1.32)

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

Change 533716 merged by jenkins-bot:
[mediawiki/core@master] ProxyLookup: Optimise in_array in isConfiguredProxy()

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

Change 533773 merged by jenkins-bot:
[mediawiki/core@master] WebRequest: Optimise WebRequest::getPathInfo()

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

Change 534476 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] build: Update wikimedia/ip-set from 2.0.1 to 2.1.0

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

Krinkle claimed this task.Sep 4 2019, 4:35 PM

Change 534476 merged by jenkins-bot:
[mediawiki/core@master] build: Update wikimedia/ip-set from 2.0.1 to 2.1.0

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

Change 533723 merged by jenkins-bot:
[mediawiki/core@master] Setup: Move MWDebug logic to MWDebug.php

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

Change 533720 merged by jenkins-bot:
[mediawiki/core@master] Setup: Move wgActionPath logic to PathRouter

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

Change 538350 had a related patch set uploaded (by Krinkle; owner: Krinkle):
[mediawiki/core@master] Setup: Move wgArticlePath validation to its main consumer (PathRouter)

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

Krinkle updated the task description. (Show Details)Sep 21 2019, 12:14 AM
Krinkle removed Krinkle as the assignee of this task.Sep 30 2019, 2:26 AM
Krinkle updated the task description. (Show Details)

Change 538350 merged by jenkins-bot:
[mediawiki/core@master] Setup: Move wgArticlePath validation to its main consumer (PathRouter)

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

Krinkle updated the task description. (Show Details)
MaxSem added a subscriber: MaxSem.Fri, Oct 25, 6:16 AM