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
17.64k stars 1.69k forks source link

[BUG] Get Rows function #1874

Closed iraj720 closed 2 months ago

iraj720 commented 2 months ago
image_2024_04_11T08_13_58_086Z

there is a problem when using these kind of .xlsx files in GetRows funciton it will add all rows and it will allocate huge amount of memory and then it will use only 0:max elements untill GC clocks makes it unable to run service with limited memory

here is the file to reproduce it :

cost_center_matrix.xlsx

  1. add the following lines to (rows.go#L77): fmt.Println(max) fmt.Println(len(results))
  2. read it normally and check the memory usage with this code after reading it: var memStats runtime.MemStats runtime.ReadMemStats(&memStats) fmt.Printf("memory allocated: %d\n", memStats.Alloc) runtime.GC() runtime.ReadMemStats(&memStats) fmt.Printf("memory allocated 2: %d\n", memStats.Alloc)

difference between 2 prints is the unnecessary allocation

https://github.com/qax-os/excelize/blob/master/rows.go#L61-L79

xuri commented 2 months ago

Thanks for your pull request. I have merged this, and this patch will be released in the next version.