Optimize XLSX subtable detection memory usage

Closed
CY
13d ago
+531-34

Summary

Replace worksheet-sized NetworkX graph construction with traversal over populated cells. Preserve four-neighbor connectivity, row-overlap merging, element ordering, text, HTML, and metadata. NetworkX remains a test dependency for comparison with the previous algorithm, and is removed from the XLSX runtime extra.

Compatibility

No new file-size, row, cell, or processing limit is introduced. Parsing, populated-cell semantics, and table rendering are unchanged. Exact serialized output matches the old algorithm for generated multi-sheet workbooks across header/HTML options and six existing XLSX fixtures. This is evidence of compatibility, not a guarantee for every possible workbook. Pandas still materializes worksheet data and a boolean mask; memory is reduced, not capped.

Validation

Synced with current main on October 1, 2026 (released as 0.27.15).

  • XLSX suite: 88 passed, including all 512 possible 3x3 occupancy patterns compared with the legacy NetworkX algorithm.
  • Exact serialized-output parity: six existing workbooks and generated multi-sheet workbooks with four header/HTML combinations.
  • Ruff and lock consistency checks passed.
  • Fresh component-detection benchmark, three repetitions per case:
CaseSparse seconds / additional sampled-peak MBDense seconds / additional sampled-peak MB
Dense table0.0100 / 6.40.0318 / 19.1
Sparse wide edges0.0035 / 1.95.8608 / 1573.5
Separated blocks0.0034 / 0.20.8578 / 200.7

These measure component detection, not total API latency. Peak RSS is sampled every 5 ms, so it is a lower bound on the true peak.