← 输入框|github.com|刷新
Skip to content

Perf/reduce allocations - #767

Merged
appel1 merged 3 commits into
developfrom
perf/reduce-allocations
Oct 3, 2026
Merged

appel1 merged 3 commits into
developfrom
perf/reduce-allocations

Conversation

@appel1

@appel1 appel1 commented Oct 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Reduce allocations in XML string reading and custom number-format parsing without changing the public API or existing parsing behavior.

  • Build XLSX and SpreadsheetML strings lazily, avoiding intermediate buffers for single-fragment values.
  • Decode OOXML escapes using spans on supported targets.
  • Replace number-format token substrings with source ranges and reuse token storage across sections.
  • Parse only the validity/date/duration classifications needed by readers, removing unused section models and copied token lists.
  • Validate numeric slices using spans where available, retaining compatible fallbacks on older targets.

Allocation and performance results

Measurements used BenchmarkDotNet on .NET 10, with warmed, repeated runs on the same machine. Allocations below are bytes per benchmark operation; XML workloads read generated workbooks, while parser workloads parse one format.

XML strings

Workload Allocated before → after Allocation reduction Elapsed-time reduction
Single-fragment inline strings 555,360 → 403,360 B 27% 6.5%
Single-fragment shared strings 660,304 → 508,304 B 23% 10.7%
Single-fragment SpreadsheetML text 1,833,765 → 1,681,765 B 8% 2.1%
Valid OOXML escapes 2,171,624 → 523,624 B 76% 38.8%
Long escape-heavy strings 66,647,600 → 33,239,376 B 50% 39.0%

Multipart/rich-text workloads retain their existing allocations, with no statistically meaningful throughput regression.

Number-format parsing

The final range-based refactor reduced short-format allocations by approximately 75–90% and elapsed time by 56–78% compared with its immediate baseline, which already included the earlier parser improvements.

Format/workload Allocated before → after Allocation reduction Elapsed-time reduction
0 616 → 152 B 75% 69.2%
0.00 1,080 → 152 B 86% 74.6%
# ?/? 1,208 → 240 B 80% 71.2%
#,##0.00;[Red]-#,##0.00 3,536 → 392 B 89% 77.7%
[>=100]0.00;[Blue][h]:mm:ss 2,496 → 240 B 90% 64.6%
yyyy-mm-dd hh:mm:ss.000 1,840 → 392 B 79% 56.2%
Long date pattern 49,256 → 8,448 B 83% 54.0%
Long digit pattern 140,680 → 33,072 B 76% 60.6%
Repeated bracket directives 54,328 → 152 B 99.7% 70.2%

The parser is not allocation-free: the format object and temporary token collection still allocate.

Whole-file guardrails

The final parser comparison also showed lower elapsed times for representative workbooks:

Workbook Elapsed-time reduction
BigFormatted.xls 17.9%
BigFormatted.xlsx 7.5%
LotsOfSheets.xls 4.5%
LotsOfSheets.xlsb 3.4%
LotsOfSheets.xlsx 5.2%

These are workload-specific measurements, not a promise of universal speedups. No statistically meaningful slowdown was detected in the accepted benchmark comparisons. Results from separate optimization stages are reported independently rather than adding their percentages together.

appel1 and others added 3 commits October 3, 2026 16:32
Lazily assemble XLSX and SpreadsheetML text fragments and decode OOXML escapes without regex allocations on modern targets. Add regression coverage and allocation benchmarks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Accumulate classification flags without retaining parsed sections and parse condition numbers from spans on supported targets. Expand format regression coverage and benchmarks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace temporary token strings and unused section models with classification-only parsing. Preserve existing behavior with frozen runtime-specific characterization fixtures and expand long-format benchmarks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@appel1
appel1 merged commit c55108a into develop Oct 3, 2026
1 check passed
@appel1
appel1 deleted the perf/reduce-allocations branch October 3, 2026 21:54
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.

1 participant