We should amortize per-request overheads by batching API requests.
AFAIK there is no generic batching support in the API currently, and adding it would probably be a bit too time-consuming for now. Instead we can add a unique string as a separator, for example something like
<nowiki>d41d8cd98f00b204e9800998ecf8427e</nowiki>
This would work for for action=expandtemplates and action=parse which are the main workarounds we currently use. In the longer term we should switch to explicit methods that don't involve parsing wikitext, which is probably also a good moment to add real batching support.
Decisions about batch sizes could be based on wikitext source size initially (based on the assumption that templates with a bazillion parameters also take longer to expand). A fixed number of templates per batch would be another simple alternative. Really fancy batching could use stats of previous processing times (returned by the PHP preprocessor per transclusion and stored in HTML).
Ideally we would also enforce separation between batched requests to avoid non-deterministic behavior for stateful extensions.
Version: unspecified
Severity: enhancement