unison icon indicating copy to clipboard operation
unison copied to clipboard

Docs are overly complex and render very slowly

Open ChrisPenner opened this issue 1 year ago • 1 comments

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.

ChrisPenner avatar Sep 24 '24 20:09 ChrisPenner