Page MenuHomePhabricator

Support parallel parsing logic in the Math implementation targeting Parsoid
Open, Stalled, HighPublic

Description

Context

Currently, the Math extension is supported during Parsoid parses by the implementation targeting the legacy parser. This does work, except for the fact that every invocation of Math is independent during a Parsoid parse, which currently makes it impossible to take advantage of the MultiHttpRequest that is used to batch multiple requests to Mathoid.

T268785 suggests moving the parallel parsing logic to core, which would clean up this mechanic and make it re-useable for other extensions. We could then imagine a way to plug that into a Parsoid-targeting implementation (although it's not entirely clear how).

Task

This task considers a different and smaller scope, namely "create enough enough of a Parsoid-targeting implementation to support the parallel Mathoid requests used in the legacy-targeting implementation. The scope of this task is limited to this specific use case (almost: see caveats section) and does not intend to create a full Parsoid-targeting implementation of the Math extension".

How

The idea would be to implement some Parsoid tag handling inside the Math extension. We foresee it would require the following:

  • an ExtensionTagHandler, implementing the sourceToDom method. This would replace the invocations to the Math extension requiring a batch processing by a placeholder, typically a <meta> tag containing the relevant information.
  • a DOMProcessor, implementing the wtPostprocess method. This would traverse the tree generated by previous invocations, gather all <meta> tags, create the corresponding batch queries and replace the elements with the final rendered elements, in the same way the parserAfterTidy does it for legacy.
  • the extension would only register the tag (via ExtensionModule::getConfig) when it is needed - i.e. when $wgMathSvgRenderer === restbase.

Caveats

  • The exact rendering mode can depend on the user preferences, passed to the parser via ParserOptionsRegister. This is fine, but we do not currently pass ParserOptions to the ExtensionAPI - this needs to be discussed. As a first step, handling this unconditionally with a large TODO is good enough for the first version of the patch (not necessarily for the first *merged* version of the patch, though.) Note that, a priori, we do NOT want to handle the *loading* of the extension depending on the user preferences: this would split the cache on user preferences whether the page has Math content or not.
  • $wgMathSvgRenderer is also controlling the rendering via mathmlcli, which *also* has a batch processing mechanism, which would be good to handle as well. (This is the second use case that we swept under the rug in the "task description" section.)
  • the Math extension also defines a couple of hooks, which are then used by MathSearch, and pass a parser to them. There are things to be discussed there as well (most probably: modify the hooks so that they do not pass a full parser, which it seems they only use to get a revId; to be confirmed with more investigations.)

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript
ihurbain renamed this task from Support parallel parsing logic in the Math implementation targetting Parsoid to Support parallel parsing logic in the Math implementation targeting Parsoid.Jul 10 2025, 5:21 PM

Change #1169109 had a related patch set uploaded (by OSleger; author: OSleger):

[mediawiki/extensions/Math@master] ParsoidHandlers: Added support for parsoid hooks and processing.

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

Change #1181748 had a related patch set uploaded (by OSleger; author: OSleger):

[mediawiki/extensions/Math@master] RendererFactory: Separate the determineMode from the getRenderer method.

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

Change #1181749 had a related patch set uploaded (by OSleger; author: OSleger):

[mediawiki/extensions/Math@master] HookRunner: Add new hook MathFormulaPostRenderContext.

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

Change #1181750 had a related patch set uploaded (by OSleger; author: OSleger):

[mediawiki/extensions/Math@master] [DNM] HookRunner: Remove MathFormulaPostRender

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

Change #1181750 abandoned by OSleger:

[mediawiki/extensions/Math@master] [DO NOT MERGE YET] HookRunner: Remove MathFormulaPostRender

Reason:

Another solution cretated

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

Change #1182140 had a related patch set uploaded (by OSleger; author: OSleger):

[mediawiki/extensions/Math@master] Hard deprecation of hook MathFormulaPostRender

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

Change #1181748 merged by jenkins-bot:

[mediawiki/extensions/Math@master] RendererFactory: Separate the determineMode from the getRenderer method.

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

Change #1186995 had a related patch set uploaded (by OSleger; author: OSleger):

[mediawiki/extensions/MathSearch@master] MathSearchHooks: Add support for hook MathFormulaPostRenderContext

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

Change #1181749 merged by jenkins-bot:

[mediawiki/extensions/Math@master] HookRunner: Add new hook MathFormulaPostRenderRevision.

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

Change #1186995 merged by jenkins-bot:

[mediawiki/extensions/MathSearch@master] MathSearchHooks: Replace hook with MathFormulaPostRenderRevision

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

Change #1182140 merged by jenkins-bot:

[mediawiki/extensions/Math@master] Removal of hook the MathFormulaPostRender

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

Change #1194313 had a related patch set uploaded (by Physikerwelt; author: Physikerwelt):

[mediawiki/extensions/MathSearch@master] Fix: Update maintenance script to use new hook

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

Change #1194313 merged by jenkins-bot:

[mediawiki/extensions/MathSearch@master] Fix: Update maintenance script to use MathFormulaPostRenderRevision

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

MSantos triaged this task as Medium priority.Nov 21 2025, 10:27 AM
Physikerwelt changed the task status from Open to Stalled.Jan 14 2026, 10:31 PM
Physikerwelt moved this task from Inbox to Blocked: needs help on the Math board.
Physikerwelt subscribed.

I have this patch set https://gerrit.wikimedia.org/r/c/mediawiki/extensions/Math/+/1169109 in my review list, but it somehow seems to be stalled.

MSantos raised the priority of this task from Medium to High.Jul 3 2026, 10:42 AM
MSantos subscribed.

We are looking forward to unblock mathoid deprecation and with all Wikipedias using Parsoid this is potentially in the critical path.