qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
18.14k stars 1.71k forks source link

The NewStyle(style *Style) memory replication of too many times #1505

Open zjfGH opened 1 year ago

zjfGH commented 1 year ago

Locality: NewStyle() -> f.getStyleID() -> range ss.CellXfs.Xf

styles.go:2116

code: for xfID, xf := range ss.CellXfs.Xf { if getXfIDFuncs["numFmt"](numFmtID, xf, style) && getXfIDFuncs["font"](fontID, xf, style) && getXfIDFuncs["fill"](fillID, xf, style) && getXfIDFuncs["border"](borderID, xf, style) && getXfIDFuncs["alignment"](0, xf, style) && getXfIDFuncs["protection"](0, xf, style) { styleID = xfID return styleID, err } }

range and getXfIDFuncs will copy each of the xf elements, consumes a lot of performance。

xuri commented 1 year ago

Thanks for your issue. How many new styles did you create, how much did memory cost in your case? and what expected you want? Could you follow the issue templates to provide more details about this issue?

zjfGH commented 1 year ago

1.Each file to perform new styles twice, A total of 200 calls. 2.Consumes 2g 10 c when case running.

  1. Memory consumption is acceptable, but the cup is too high. Hope can optimize the new styles 's execution time

About this case pprof sample: pprof imgs.docx