The ColumnNumberToName function previously concatenated rows using the + operator, leading to significant memory allocation when called frequently.
The function now uses a pre-allocated slice to build the Excel column name. During construction, the converted number to letter is added to this slice. At the end, the slice of runes is converted to a string and returned.
Sheet Pre-allocation:
Added an option to create a Sheet with pre-allocated rows.
The xlsxWorksheet structure now contains a field with a slice type. When calling the SetCell... function to add a row to the sheet, it in turn calls the prepareSheetXML function. This function adds an xlsxRow structure to the slice.
Previously, multiple calls to prepareSheetXML caused the slice to grow, allocating a lot of memory and performing unnecessary copying. The new approach pre-allocates the maximum number of rows, reducing memory allocations and copying overhead.
Related Issue
Resolves Issue #XXX
Motivation and Context
When working with a lot of data, some functions create many objects and trigger garbage collection (GC). The GC then loads the processor.
This optimization reduces memory allocations and the associated GC overhead, improving performance.
How Has This Been Tested
The changes have been tested in a development environment with datasets of varying sizes.
Benchmark tests were added to measure performance improvements in memory usage and processing time.
Existing unit tests were run to ensure no regressions were introduced.
PR Details
Optimizing memory usage by pre-allocation.
Description
ColumnNumberToName Function:
ColumnNumberToName
function previously concatenated rows using the+
operator, leading to significant memory allocation when called frequently.Sheet Pre-allocation:
xlsxWorksheet
structure now contains a field with a slice type. When calling theSetCell...
function to add a row to the sheet, it in turn calls theprepareSheetXML
function. This function adds anxlsxRow
structure to the slice.prepareSheetXML
caused the slice to grow, allocating a lot of memory and performing unnecessary copying. The new approach pre-allocates the maximum number of rows, reducing memory allocations and copying overhead.Related Issue
Motivation and Context
How Has This Been Tested
Types of changes
Checklist
Feel free to modify any part of this to better fit your needs!