Page MenuHomePhabricator

Improve Perfomance of TexVC PHP in Math
Closed, ResolvedPublic

Description

Some tests are running very slow. Improve perfomance issues which come
from multiple instantiations of TexUtil in the node-classes.

With each instance creation TexUtil loads a json file from filesystem.

Use profile for checking the time and number of calls for each method:
https://www.jetbrains.com/help/phpstorm/profiling-with-xdebug.html#snapshotLocation

Related Objects

StatusSubtypeAssignedTask
DeclinedStegmujo
OpenNone
ResolvedPhysikerwelt
ResolvedPhysikerwelt
ResolvedStegmujo
Resolvedmmartorana
ResolvedPhysikerwelt
ResolvedStegmujo
DuplicateStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedPhysikerwelt
ResolvedStegmujo
DuplicateStegmujo
DuplicateStegmujo
DeclinedStegmujo
DeclinedStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedNone
ResolvedStegmujo
ResolvedStegmujo
ResolvedPhysikerwelt
ResolvedPhysikerwelt
DuplicateNone
ResolvedStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedStegmujo
ResolvedSalixAlba
DeclinedPhysikerwelt
ResolvedStegmujo
ResolvedBUG REPORTStegmujo
ResolvedBUG REPORTStegmujo
ResolvedBUG REPORTPhysikerwelt
ResolvedBUG REPORTPhysikerwelt
ResolvedBUG REPORTPhysikerwelt
ResolvedBUG REPORTPhysikerwelt
ResolvedBUG REPORTPhysikerwelt
ResolvedBUG REPORTPhysikerwelt
ResolvedPhysikerwelt
ResolvedPhysikerwelt
ResolvedPhysikerwelt
ResolvedBUG REPORTStegmujo
ResolvedStegmujo
InvalidNone

Event Timeline

Note that in https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/872952 the checking performance was increased.

My feeling is that the overall performance is not slower than doing a request to mathoid and waiting for the response.

Notes in analyzing profile output for "MMLFullCoverageTestLocal.php":
~ encapsulate and encapsulateRaw work a bit differently locally.

From Literal::renderMML:

  • BaseMethods::checkAndParseOperator gets called very often, rearrange the sieves here, check if calls to root method can be specified ?

From TexNode::parseToMML():

  • Requires 7,6 % time. This method is directly called from several renderMML methods, this then calls checkAndParse to proceed through all sieves to reduce the required time, the sieves (and the corresponding check methods) could be more specified by TexVC-Node.

Done:

  • BaseMethods::checkAndParse is taking much time here, maybe shift order or reduce the cascadic checks in a way? : It is already the last check in the order. Done through rearranging the cascade by stat. distribution of method calls

From TexNode::renderMML():

  • array_reduce takes 5,9 % time, maybe there is an alternative for it, double check whether array_reduce takes so much time or the internal callbacks. : it is 5,8 % time taken by callbacks ....

From checkAndParse:

  • MMLutil::inputPreparation is called very often and takes 1,3 % time -> optimize number of calls and timing?
  • baseParsing::mathFont has 120 calls and takes 2,6 % time : conclusion there is not much to optimize in this method

Change 903611 had a related patch set uploaded (by Stegmujo; author: Stegmujo):

[mediawiki/extensions/Math@master] Fix perfomance in ...

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

Change 903551 had a related patch set uploaded (by Stegmujo; author: Stegmujo):

[mediawiki/extensions/Math@master] Improve performance: other

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

Statistical analysis from EnWikiFormulaeTest for the distribution of resolved mappings in BaseMethods::checkAndParse :

BaseMappings::getMhChemByKey = {int} 39380
BaseMappings::getMacroByKey = {int} 9249
AMSMappings::getMacroByKey = {int} 369
AMSMappings::getEnvironmentByKey = {int} 207
BaseMappings::getCustomByKey = {int} 167
BaseMappings::getSpecialByKey = {int} 96
BaseMappings::getcancelByKey = {int} 0

Change 903551 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Improve performance: arrange methods by call probability

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

Change 903611 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Improve performance: remove redundant inputPreparation calls

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