Page MenuHomePhabricator

Migrate code away from use of PHPDOM's getElementsByTagName which has non-linear perf characteristics
Open, Needs TriagePublic

Description

T317070 and T215000 both dealt with non-linear performance of getElementsByTagName in PHP DOM's implementation.

Unless someone wants to take on fixing PHP DOM's implementation, we should replace its use in our code bases with Zest::find or Parsoid's DOMCompat::querySelectorAll or DOMCompat::getElementsByTagName both of which are wrappers around Zest.

DOMCompat::findElementsByTagName seems the simplest replacement since it leaves open the possibility of easy switching back if/when PHP DOM perf gets fixed.

Code search reveals Flow, DonationsInterface, Translate, GWToolset, TextExtracts all use this method (https://codesearch.wmcloud.org/search/?q=getElementsByTagName&i=nope&files=php&excludeFiles=)

@Esanders also says: "And also a lint rule to prevent it being used in the future."

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

The uses in Translate are a maintenance script and Xliff file format handler which is currently unused: https://codesearch.wmcloud.org/search/?q=getElementsByTagName&i=nope&files=php&excludeFiles=&repos=Extension:Translate

What replacements are present in MediaWiki core version 1.37 and above?

Jdforrester-WMF added a subscriber: Jdforrester-WMF.

The uses in Translate are a maintenance script and Xliff file format handler which is currently unused: https://codesearch.wmcloud.org/search/?q=getElementsByTagName&i=nope&files=php&excludeFiles=&repos=Extension:Translate

What replacements are present in MediaWiki core version 1.37 and above?

The mentioned Zest::find is present in 1.37 (indeed, since 1.35.0-wmf.20):

https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/vendor/+/refs/heads/REL1_37/wikimedia/zest-css/src/Zest.php#41

The easy fix is to replace $node->getElementsByTagName( $tag ) with Zest::getElementsByTagName( $node, $tag ) (which unlike find has identical signature).

Change 831201 had a related patch set uploaded (by Catrope; author: Catrope):

[mediawiki/core@master] VueComponentParser: Use Zest's getElementsByTagName() rather than PHP's

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

Change 831201 merged by jenkins-bot:

[mediawiki/core@master] VueComponentParser: Use Zest's getElementsByTagName() rather than PHP's

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