unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

Docs are overly complex and render very slowly #5368

Open ChrisPenner opened 1 month ago

ChrisPenner commented 1 month ago

Docs are parsed into Unison terms one-word-at-a-time, which means a doc with 2000 words has at LEAST 2000 function calls 🙃 .

Even worse, the way it's resolved, it doesn't even resolve to a Doc literal, it resolves to a tree full of docWord calls:

docWord : Text -> Doc
docWord = Word

Which is a function, which must be evaluated on a text argument, which then actually calls the constructor, which returns the Doc.

Some ways to clean this up would be to:

  1. Cut one-level of wrapping by aliasing the doc syntax directly to the appropriate constructors where possible, this would remove one layer of function calls universally (but would change the hash of every doc on roundtrip once after we make the change).
  2. Eagerly combine words into larger text chunks directly in the parser, We'd still need to split off any text with syntax elements like bold/italics/links.
aryairani commented 1 month ago

Q: Main issue is that docs are slow to render, but why?

Consider caching failed runs (e.g. todo); possibly key the cache on the set of builtins? Maybe slow to evaluate docs due to lots of postgres traffic?

Next step: Identify a slow doc (e.g. TV/README) and profile it to figure out why it's actually slow. Seems like it's loading all the code that's mentioned, not just code that needs to be executed; hopefully we can avoid that.