Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Performance: Cache column indexes #80

Open
bocca opened this issue Aug 2, 2022 · 0 comments
Open

Performance: Cache column indexes #80

bocca opened this issue Aug 2, 2022 · 0 comments

Comments

@bocca
Copy link

bocca commented Aug 2, 2022

Classes such as ColumnNameReader and ColumnNameMatchingValueReader compute column indexes for every row. This is not necessary and degrades performance, as indexes do not depend on the row index. The API could be refactored to allow to compute indexes only once at Header creation, and then use indexes only.

For example:

public interface ISingleCellValueReaderFactory
{
    ISingleCellValueReader TryGetReader(ExcelSheet sheet, IExcelDataReader reader);
}

public class ColumnNameValueReaderFactory : ISingleCellValueReaderFactory
{
    public string ColumnName { get; }

    public ColumnNameValueReaderFactory(string columnName)
    {
        ColumnName = columnName;
    }

    public ISingleCellValueReader? TryGetReader(ExcelSheet sheet, IExcelDataReader reader)
    {
        return sheet.Heading.TryGetColumnIndex(ColumnName, out int index)
            ? new ColumnIndexValueReader(index) : null;
    }
}

And then:

propertyMap.WithReaderFactory(new ColumnNameReaderFactory())
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant