Skip to content

Cache the column mapping count in CellReferenceConverter - #1023

Merged
michelebastione merged 1 commit into
mini-software:masterfrom
virzak:fix/column-mapping-count
Oct 15, 2026
Merged

michelebastione merged 1 commit into
mini-software:masterfrom
virzak:fix/column-mapping-count

Conversation

@virzak

@virzak virzak commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1024

EnsureMappingsUpTo checked IntMappingToAlphabet.Count, and ConcurrentDictionary.Count takes every internal lock. Querying without a header row calls it for every cell. The count is now cached in a volatile field, which is safe because entries are only added, contiguously from 0.

QueryExcelBenchmark on net10.0:

Method master this PR
MiniExcel Query 3,878.82 ms 399.45 ms
MiniExcel Query with Mapping 331.35 ms 320.11 ms

Allocations are unchanged.

Summary by CodeRabbit

  • Performance
    • Reduced repeated mapping-count lookups while preserving existing column limits and mapping behavior.

…y.Count

Count takes every internal lock, and it ran for every cell of a query
without a header row.
@coderabbitai

coderabbitai Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0110db36-fcd7-4ae7-a308-f3d8a710190e
📥 Commits

Reviewing files that changed from the base of the PR and between 6175350 and 97785d7.

📒 Files selected for processing: 1
  • src/MiniExcel.Core/Helpers/CellReferenceConverter.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

📝 Walkthrough

EnsureMappingsUpTo now checks a volatile cached mapping count instead of reading ConcurrentDictionary.Count on each call. After adding mappings, it refreshes the cached count. The existing column-limit check and mapping behavior remain unchanged.

Changes: Mapping count cache

Layer / File(s) Summary
Cache and use mapping count
src/MiniExcel.Core/Helpers/CellReferenceConverter.cs
A volatile field stores the mapping count. EnsureMappingsUpTo checks it before adding mappings and refreshes it afterward.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 97785

No concrete correctness, availability, or compatibility risk is supported by the change. It appears mergeable subject to normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main change: caching the column mapping count in CellReferenceConverter.
Linked Issues check Passed Issue #1024 requires reducing the per-cell cost of EnsureMappingsUpTo, which previously read ConcurrentDictionary.Count. The reviewed CellReferenceConverter adds volatile _mappedCount, uses it…
Out of Scope Changes check Passed The reviewed change is limited to the mapping-count cache in src/MiniExcel.Core/Helpers/CellReferenceConverter.cs. The cache supports the issue #1024 performance objective and does not introduce unr…
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@michelebastione
michelebastione merged commit e68503c into mini-software:master Oct 15, 2026
4 checks passed
@virzak
virzak deleted the fix/column-mapping-count branch October 15, 2026 12:31
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.

Querying without a header row is 2.6x slower than querying with mapping

2 participants