USPTO backend: table extraction regex is quadratic in document size
Author: dolfim-ibmCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbugxmlperformance
### Bug
The USPTO XML backend extracts tables with the regex `^()`, compiled with `re.MULTILINE | re.DOTALL`, in three places in `docling/backend/xml/uspto_backend.py`. When a document contains many ``, each match attempt scans to the end of the input, so extraction time grows quadratically with the document size. `document_timeout` does not interrupt it, because the work happens inside a single `re.findall` call.
Measured timings: 18 KB takes 0.09 s, 36 KB takes 0.35 s, and 72 KB takes 1.42 s.
Proposed fix: replace the regex scan with a linear search for the matching `
`, or extract tables with the XML parser.
### Steps to reproduce
Convert a USPTO patent XML file whose body contains thousands of unterminated `
Source: docling-project/docling