Expand description
A pre-parse bound on document complexity.
html5ever’s tree builder rescans its stack of open elements when it inserts
certain tags, so parse time grows quadratically with nesting depth. Measured
on this crate: 4 000 nested <div>s parse in 0.09 s, 16 000 in 1.7 s, and
200 000 — a 2.2 MB file, comfortably inside the 5 MiB body cap — took over
four minutes. Neither the body cap nor --timeout helps: the cap counts
bytes, and the timeout covers the HTTP request, not the parse that follows.
On the MCP server that stall blocks every other request.
So depth is measured up front, in one linear scan, and a document past the
limit is refused rather than parsed. Real pages sit around depth 20-50;
MAX_NESTING_DEPTH is far above anything a document written for humans
reaches, so the check only fires on pathological input.
Constants§
- MAX_
NESTING_ DEPTH - Nesting depth past which a document is refused.
Functions§
- max_
nesting_ depth - Estimate a document’s maximum element nesting depth.
- too_
deeply_ nested - Is this document too deeply nested to parse within a sane time budget?