Skip to content

perf: Clip column range instead of filtering in V2 DataLocator - #1032

Open
nightscape wants to merge 2 commits into
mainfrom
fix/v2-large-colind-perf
Open

perf: Clip column range instead of filtering in V2 DataLocator#1032
nightscape wants to merge 2 commits into
mainfrom
fix/v2-large-colind-perf

Conversation

@nightscape

Copy link
Copy Markdown
Owner

Summary

  • Replaces colInd.filter(_ < r.getLastCellNum) with direct range clipping (colInd.start to min(colInd.last, lastCellNum - 1)), avoiding O(maxColumns) iteration per row
  • Hoists getLastCellNum evaluation to once per row instead of once per column index
  • Supersedes Use takeWhile method from Range #720 with a more efficient approach (O(1) range construction vs O(n) takeWhile)

When dataAddress specifies only a starting cell, colInd becomes 1 to 16383. For a file with 1M rows and 23 actual columns, the old code performed ~16 billion unnecessary comparisons. This change eliminates them entirely.

Test plan

  • Existing integration tests pass (43/45, 2 pre-existing flaky failures in returns all data rows when inferring schema)

🤖 Generated with Claude Code

When dataAddress specifies only a starting cell, colInd becomes a huge
range (e.g. 1 to 16383). The previous code iterated the entire range
per row using .filter(), causing O(rows * maxColumns) comparisons.

Replace with direct range clipping: colInd.start to min(colInd.last,
lastCellNum - 1). This is O(1) per row and also hoists the
getLastCellNum call out of the per-element evaluation.

Fixes #720

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 31, 2026 21:40
@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Improves the performance of V2 Excel reading by avoiding per-row iteration over the full maximum Excel column range when dataAddress specifies only a starting cell.

Changes:

  • Introduces a helper to read row cells with column-range clipping based on Row.getLastCellNum.
  • Hoists getLastCellNum evaluation to once per row and replaces Range.filter with O(1) effective-range construction.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/scala/dev/mauch/spark/excel/v2/DataLocator.scala Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants