← All updates

Markdown that used to hang now renders — and one new line limit

A list with a long lazy continuation, or a long run of setext headings, could keep a markdown render busy for tens of seconds before it produced anything. Both render normally now, and a document with more than 150,000 lines is refused up front with a clear error instead of stalling.

markdownapilimitsperformance

Two shapes of markdown used to bring a render to its knees, and neither was something you would have written on purpose. A list item whose text continues unindented for thousands of lines (- a followed by line after line of plain text) made the parser grind: 40KB took about 4 seconds, and 200KB about 90 seconds. A long run of setext headings (a on one line, - on the next, over and over) was worse per line — 80KB took about 6 seconds. A third variant, a table delimiter row that holds a | but a different number of cells than its header, hit the same parser rule's second check and was worse still: 80KB took about 12 seconds. All are reachable on POST /api/v1/md and on a canvas text card, so they were also a way to tie up a free render.

The cause in every case was a parser rule reading the rest of the document over and over at every block. Each rule was making a correct decision — that is what made it slow rather than wrong — so the fix is a cheap check that reaches the same decision without the scan. All of these documents now convert on their own merits: 200KB in about a second, with byte-identical output to before for every document those rules accept. Nothing about the markdown you send needs to change.

One new limit comes with it: a document may hold at most 150,000 lines. Every markdown block costs at least one line, so past that a render has more blocks than we can lay out in reasonable time. A document over the limit is refused before parsing starts, with the same typed error the API already uses for over-complex input:

{
  "code": "markdown-too-complex",
  "rule": "block-count",
  "error": "markdown is too complex to parse in reasonable time; see `hint` for the construct to change",
  "hint": "The document has more than 150,000 lines, so it has at least that many markdown blocks. Split it into several documents."
}

/api/v1/md caps markdown at 200KB of text, so its documents cannot reach the line limit at any realistic line length — this only bites on a canvas text card, which may hold 1MB. Nothing else changes: the request bodies, the response shapes and the credit price are all as they were. The full detail is in the API reference.