Performance and large files
On this page
TExcel parses worksheet XML row by row and writes ZIP entries in batches, avoiding a cell object tree for the entire worksheet. Use typed rows for fixed schemas and dictionaries for dynamic columns. Consume sequences directly and retain only the business results you need to reduce additional materialization.
Reading and writing 100,000 rows
These figures come from the published .NET 8 BenchmarkDotNet report in the TExcel README, using its Job with 3 warmups and 10 measured iterations. MiniExcel is the comparison. Complete operations include file I/O. Results from the separate ShortRun Job and other machines are not combined here.
| 100,000-row workload | TExcel mean | Compared with MiniExcel |
|---|---|---|
| Write typed rows to XLSX | 182.87 ms | 22.9% less time, 82.3% less allocation |
| Read typed rows into a list | 238.77 ms | 52.5% less time, 84.3% less allocation |
| Enumerate typed rows, count only | 223.26 ms | 40.6% less time, 84.6% less allocation |
For 100,000-row typed writes, managed allocation is 41,031.66 KB, compared with 232,293.94 KB. Streaming reads still allocate strings and entities; they avoid retaining a full result list without eliminating allocations.
Comparison by scale
Time is converted from microseconds to milliseconds. Allocation retains the report’s KB unit from Allocated. Each pair is TExcel / MiniExcel. Allocation measures cumulative managed allocation for one complete operation, not peak memory.
| Workload | Rows | Mean time, ms | Managed allocation, KB |
|---|---|---|---|
| Write typed rows | 100 | 0.971 / 3.802 | 1,794.87 / 15,687.84 |
| Write typed rows | 10,000 | 20.091 / 33.360 | 6,946.49 / 36,439.35 |
| Write typed rows | 100,000 | 182.866 / 237.299 | 41,031.66 / 232,293.94 |
| Read typed rows into a list | 100 | 0.194 / 1.894 | 151.00 / 720.82 |
| Read typed rows into a list | 10,000 | 22.787 / 52.308 | 8,571.34 / 55,438.66 |
| Read typed rows into a list | 100,000 | 238.770 / 503.109 | 87,858.84 / 558,096.67 |
| Read dictionaries into a list | 10,000 | 26.208 / 63.053 | 10,054.47 / 56,573.87 |
| Write dictionaries | 10,000 | 17.376 / 33.335 | 5,773.77 / 35,241.51 |
| Enumerate typed rows, count only | 100,000 | 223.261 / 375.842 | 85,822.90 / 556,055.82 |
Environment and measurement scope
| Item | Recorded setting |
|---|---|
| CPU | Intel Core Ultra 9 285H, 16 logical cores |
| OS | Windows 11, 10.0.26200.8246 |
| SDK / runtime | .NET SDK 10.0.201 / actual runtime .NET 8.0.25, X64 RyuJIT |
| Tool and Job | BenchmarkDotNet 0.15.8; Job-YFEFPZ, 3 warmups and 10 measured iterations |
| Typed reading | Full enumeration followed by ToList, including parsing, entity conversion and the result list |
| Streaming reading | Full enumeration and counting; still creates each entity but does not retain a complete list |
| Writing | Input prepared beforehand; operation includes producing and completing an XLSX file |
For 100,000-row typed writes, TExcel / MiniExcel standard deviations are 3.464 / 9.323 ms. Typed list reads are 16.922 / 3.751 ms, and streaming counts are 14.171 / 13.486 ms. See the original report for other errors, ranges and GC values. This historical report does not identify exact tested library commits or package versions. Its figures describe the recorded workloads; measure the version you intend to deploy on your target environment.
The current benchmark source uses six-column entities covering integers, text, floating-point values, dates and booleans, with typed, dictionary and counting methods. The current project targets .NET 10 and references MiniExcel 2.0.0. A rerun produces a new result set; those current settings do not establish the versions used in the historical .NET 8 report.
Implementation choices that reduce work
| Mechanism | Behavior | How to use it |
|---|---|---|
| Row parsing | XmlReader reads worksheet XML sequentially; an internal row buffer grows with column width and is reused | Enumerate directly instead of calling ToList before processing |
| Header binding | Typed reads bind headers to properties once, then convert subsequent rows | Prefer Query<T> / ReadSheet<T> for fixed schemas to avoid a dictionary per row |
| Optional cell facts | Ordinary reads do not collect each cell’s raw value, type and formula flag | Enable includeCellFacts only when the import contract needs them |
| Batched XML output | Write operations resolve column metadata once and flush worksheet batches; the current implementation flushes every 1,000 rows | Supply an enumerable or async sequence directly without copying it to another collection |
| Shared strings | Repeated text reuses a shared-string index | Repeated names and categories benefit; unique text still increases string-table memory |
| Fast compression | Worksheet ZIP entries use CompressionLevel.Fastest | Measure compression, file size and I/O together with conversion time |
Returned entities, dictionaries and arrays own their data; advancing the internal buffer does not overwrite them. Buffer reuse still involves allocations for decoded strings, conversions and result objects.
Bound memory for large files
Memory includes workbook state, the current row or write batch, retained application results, and output buffers. Switching to async APIs does not remove this state.
| Scenario | Recommendation | Remaining costs |
|---|---|---|
| Fixed-schema import | Enumerate Query<T> / QueryAsync<T> directly and process bounded business batches | Entities, strings and conversion; avoid an unbounded set of processing tasks |
| Dynamic preview | Use dictionaries when headers are needed and arrays for known positions | Per-row dictionaries allocate a hash table; arrays still copy each row’s values |
| Strict import | ReadSheetRows(includeCellFacts: true) | Extra cell facts; bound the number of retained error details |
| Database export | Supply the database async sequence to WriteSheetAsync and propagate cancellation | The reader and connection stay occupied; both database and output speed affect total time |
| Paged export | Create one writer, use WriteSheet for the first batch and AppendSheet for subsequent batches of that sheet | One source batch at a time; shared strings remain for the workbook lifetime |
| Large output | Prefer a file stream or another caller-owned stream with a suitable contract | MemoryStream retains the whole compressed file; ToArray copies it again |
Reading loads the workbook’s shared-string table. Writing retains unique strings and their indexes. Row processing reduces retention of worksheet objects and result lists, but memory still depends on unique text and workbook state. Multiple worksheets share that state.
Time both Complete / CompleteAsync metadata writing and writer disposal to finalize the ZIP. Deliver the file only after success. Include any worksheet-design post-processing in export timing.
Compare the two source strategies in database export: direct streaming avoids a batch list; key-based batches add round trips but finish each reader before output. Use CSV when text exchange is sufficient.
Measure a representative workbook
The standalone TExcel repository contains benchmark/TExcel.Benchmark; its entry point supports BDN --list flat and --filter. Existing TUtility_ method names are historical; their display names say TExcel. The project configures both a 10-iteration Job and ShortRun. Compare results within the same Job.
Fix row and column counts, data types, unique-text ratio, worksheet count, runtime, package versions, disk and output strategy. Match the file contents and list-retention scope, fully enumerate, then validate row counts and fields. To evaluate peak memory, separately record working-set or GC-heap peaks; Allocated cannot establish them.