SaveAs can cause excessive heap usage when saving workbooks with many large worksheet XML parts
Description
Description
We are seeing very high heap usage when calling SaveAs on workbooks created from large templates.
In our production workload, we use XLSX templates that contain many worksheets. The service opens the template, writes report data into it, and then calls SaveAs to generate the final workbook.
For some large templates, memory usage stays relatively low while opening the file and writing rows, but increases sharply during SaveAs. In one case, heap usage rose to around 1.5 GB during save. This can cause OOM in smaller production containers, for example 2 CPU / 2 GB memory containers.
The issue becomes more visible when the workbook contains many large worksheet XML parts. Those worksheet XML files can be spilled to temporary files when opening the workbook, but they are loaded back into memory during save.
Root Cause
In writeToZip, temp-file-backed entries are currently written with:
if n, err = fi.Write(f.readBytes(path)); int64(n) > math.MaxUint32 {
f.zip64Entries = append(f.zip64Entries, path)
}I will create a pr, could help check it?
Source: qax-os/excelize