#29729·amphtml

amp-mathml is painfully slow. Benchmarking amp-mathml vs. KaTeX

Author: hayesallCreated Aug 6, 2020Updated Jun 8, 2026
LabelsType: Feature RequestP2: SoonWG: componentsComponent: amp-mathmlType: Performance

Describe the new feature or change to an existing feature you'd like to see

The current version of amp-mathml seems to be based on MathJax. This is a huge bottleneck for pages with lots of math. An alternative version based on KaTeX might fix this.

Describe alternatives you've considered

The current implementation does work, but it doesn't deliver on the fast load times AMP intends to have.

Additional context

I cannot promise intend-to-implement I2I any time soon.

Benchmarks below.


The Benchmark

This benchmark is based on a summary of "Mirror Descent for Metric Learning: A Unified Approach" that includes 88 math blocks, mixed between inline blocks and equations.

Two versions of this web page were created:

  1. Based on amp-mathml
  2. Based on KaTeX

Reproducing

See this gist: https://gist.github.com/hayesall/33ba7aed8ebfbf0dba761cb7ba501342

bash
git clone https://gist.github.com/hayesall/33ba7aed8ebfbf0dba761cb7ba501342 hayesall-amp-demo
cd hayesall-amp-demo
python -m http.server    # Start an HTTP server with Python 3
AMP Complient? Method URL
No KaTeX http://0.0.0.0:8000/katex.html
Yes amp-mathml http://0.0.0.0:8000/amp-mathml.html#development=1

Preview of part of the benchmark page:

mdml_section2_border

Benchmark 1: amp-mathml

All equations were rendered after around 22,000 ms:

amp-mathml-flame-chart-border

Benchmark 2: KaTeX

There is some delay in the beginning between when I refreshed the page, but the rendering took place between 1000 ms and 1200 ms, or around 200 ms.

katex_flamegraph-border