Commit Graph
1 Commits
Author SHA1 Message Date
Roman Yurchak da8c27f3c4 perf: cap cluster_rects component size to avoid O(n²) on vector-heavy pages (#6)
Pages with tens of thousands of vector-drawing rects (e.g. architectural
plans with 36k+ rects) caused cluster_rects and sub-rect deduplication to
spend 10-50s in O(n²) loops. No real table has thousands of cell rects,
so once a union-find component exceeds 2000 elements we skip further
comparisons, and skip the O(n²) sub-rect dedup entirely for such pages.

Benchmarks on 8 slow production PDFs show 10-40x speedups on vector-heavy
files (12s→0.3s) with no regression on other file types. All 342 tests
pass.
2026-03-18 17:27:49 -07:00