Hacker News new | ask | show | jobs
by delta_p_delta_x 1489 days ago
> while no noticable slowdown for the user (it may even end up doing the "first paint" faster in the browser if GitHub are careful about their implementation).

Have you visited math.stackexchange? Pop by their MathJax reference page[0], and observe how long all the mathematical notation takes to render fully—it takes at least six seconds on my recent notebook, plugged in. On my 2018 iPad Pro, it takes well over thirty seconds on the first page load (drops to ~5 s on subsequent visits: there's probably some caching going on).

Here's[1] a benchmark comparing KaTeX (server-side), MathJax 2.7, and MathJax 3.0 (apparently a complete rewrite supporting server-side rendering[2], but it's still noticeably slower than KaTeX).

MathJax is really slow (slower still than LaTeX itself, and that's saying something).

[0]: https://math.meta.stackexchange.com/questions/5020/mathjax-b...

[1]: https://www.intmath.com/cg5/katex-mathjax-comparison.php

[2]: https://docs.mathjax.org/en/latest/upgrading/whats-new-3.0.h...

4 comments

On my machine the first link loaded in under a second. On my mobile it was about 3 seconds, but it didn't feel especially sluggish. Even then, I'd say stackexchange has a somewhat inefficient implementation, in that they're trying to render everything in one shot.

For example, I see no reason why they wouldn't just render the stuff that's in view first, and the rest is rendered incrementally as the user scrolls, or a few seconds after the initial paint.

I take your point that KaTeX is faster in absolute terms, but from a usability point of view, the benefits do not outweigh the costs in my opinion.

> the first link loaded in under a second. On my mobile it was about 3 seconds

Did you wait for the typefaces to change to Computer Modern? On my smartphone, this took ages, and that is what I implied by 'fully loaded'; more complex maths is unreadable on some devices with only the native typefaces. Even a (relatively straightforward) cube root doesn't look clean[0].

MathJax has (from my observation) two 'levels' of rendering, where it uses the OS native typeface for a first pass, and then renders everything in Computer Modern for a uniform look (except on Apple devices, which somehow override this with STIX fonts).

Needless to say, the typeface change means that the dimensions of the maths content change, causing the rest of the website to reflow a second time. This second render takes the bulk of the time, and having a website's content unexpectedly jump around a long while after it has (apparently) loaded is not exactly user-friendly.

[0]: https://imgur.com/a/CrKqeI5

I wonder about your setup. On an iPhone 12 on residential wifi behind a VPN, I noticed no lag, delayed rendering, or weird rendering issues.
I can confirm that MathJax is very slow, especially if you render complex math including graphs (all in view). The Google Lighthouse Benchmark gave me a very bad performance score, but as soon as I switched to Katex my statically rendered blog gets 95-100 points for performance.
> [...] observe how long all the mathematical notation takes to render fully—it takes at least six seconds on my recent notebook, plugged in.

Does this really matter though? When I've encountered math-heavy pages that have been slow to fully render the math has also been slow for my brain to processes. As long as the math rendering is faster than my brain's math understanding it has been fine.

On my iPad Pro (2018), the first page rendered fully within seconds. I’d never visited the page before. I scrolled down and up the entire page to check.
On my mobile, for [1] KaTex loads in 900ms, MathJax in 1200-1600ms. Good enough for client side usage.