Page MenuHomePhabricator

startup.js runs O(n²)
Open, Needs TriagePublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Register some user scripts (e.g., TMg autoformatter, etc.).
  • turn article preview off,
  • Open dozens of tabs in edit mode,
  • Wait until all icons are loaded.

What happens?:

  • it takes time until all icons in edit-toolbar are loaded.
  • startup.js line 747(↓) runs once for each js file, which results in O(n²) for each .js file added to Mediawiki.
// Stage 2: Execute 'loaded' modules with no unsatisfied dependencies
for ( module in registry ) {

What should have happened instead?:

  • startup should be faster

Software version (on Special:Version page; skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

Event Timeline

To be more exact, that loop looks like it does O(n×m) operations, where n is the number of registered modules (around 1000 in production), and m is the depth of the dependency tree (around 20).

@Boshomi_Phabricator Let's come back to the for-loop later. Can you say more about the original problem you experienced?

Which edit toolbar are you referring to? You can find a list a https://www.mediawiki.org/wiki/Editors

Are you referring to the toolbar itself loading slow (including the default buttons in it), or are you referring to custom buttons that a gadget or your user script is adding to the toolbar?

Which browser are you using?

What is "article preview"?

  • the Popups extension ("Enable page previews" reading preference, applicable when reading articles and hovering links)
  • the live preview feature ("Show preview without reloading the page" editor preference)
  • the first preview feature ("Show preview when starting to edit" editor preference)
  • the WikiEditor preview sidebar ("Preview" button in the WikiEditor extension toolbar above the edit form)

Why did you turn off article preview? Was it making it worse/distracting, or did the issue not happen when it's enabled?

Idem for user scripts, if you turn off gadgets and user scripts, does the issue happen? If not, what's the minimum needed to cause the issue? Something may be going on there.