Skip to content

The cost of merged cell filling is extremely high for LINQ queries. #837

Open

Description

@ZuoWangDao6

Enabling merged cell filling (FillMergedCells = true) has a significant performance impact on LINQ queries, even when using simple operations like .Skip() or .First().

In our case, after setting:

var a = MiniExcel.Query(@"D:\Test1,000,000x10.xlsx", configuration: new OpenXmlConfiguration() { FillMergedCells = true }).First();

went from 56ms to over 9000ms.

Activity

  1. menes97 commented on Nov 19, 2026

    @menes97
    Member

    Reproduced on master (c7fb0bd, v2 API, net10.0). I used a 300k rows × 10 columns sheet that has a <dimension> element, as Excel writes it:

    FillMergedCells Query(path).First()
    false ~0 ms
    true ~700 ms (675 and 742 ms in two runs)

    The cause: OpenXmlReader.InternalQueryRangeAsync calls TryGetMergeCellsAsync before it yields the first row. That method (OpenXmlReader.MergeCells.cs, around line 21) loops while (await reader.ReadAsync()) over every node of the sheet to reach <mergeCells>, which the schema places after <sheetData>. In my file that is about 18M nodes, so the whole sheet is tokenized before row 1 comes back, and the cost grows with the file size.

    For comparison, in a stand-alone test on the same sheet entry:

    • a plain XmlReader pass took 550–1200 ms;
    • just inflating the entry took 55–80 ms.

    A raw scan for the mergeCells element that parses only from there could remove most of the cost, but I haven't implemented or tested that inside MiniExcel.

    Workaround for now: leave FillMergedCells off when you only need the first rows, or read once and cache the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions