even on 5 pages documents LaTeX can spend a surprising amount of time
What five page documents? I've seen it zip through far larger texts on the regular.
And is most of the effort from LaTeX in paragraph layout? Most slowness there, is in Mathematica typesetting, I would think.
Is Latex text wrapping known to be well optimized?
The main algorithm most any folks know by name for doing this was created for it, so sorta? I don't know that it is necessarily better than any closed source options. I was under the impression it is the baseline good, though.
Its author was supposedly pretty good at algorithms. I think he may have even written a book or four about them. So I suspect it’s decently optimized.