-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
optimize memory allocation #722
Conversation
Codecov Report
@@ Coverage Diff @@
## master #722 +/- ##
=======================================
Coverage 96.65% 96.65%
=======================================
Files 31 31
Lines 8553 8557 +4
=======================================
+ Hits 8267 8271 +4
Misses 163 163
Partials 123 123
Continue to review full report at Codecov.
|
sheet.go
Outdated
@@ -64,6 +64,19 @@ func (f *File) NewSheet(name string) int { | |||
return f.GetSheetIndex(name) | |||
} | |||
|
|||
// NewSheetWithRowNum provides the function to create a new sheet by given a worksheet and a given number of rows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new API seems unnecessary, SetCellValue will preallocate cells for any new worksheets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometime will need this. Realloc cause huge GC pressure.
Example:
I need export a million row form db and write into excel, data is encrypt , need decrypt .
slice often realloc we cause huge GC pressure 、copy spending
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have encountered this situation before.
l remember alloc 1-3G mem. it's too Impressive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for my late reply. We can using streaming API NewStreamWriter
to generate huge data spreadsheet, by evaluation and follow the principle of least availability, I don't purpose to add this API. If you have any questions, let me know.
@xuri use NewStreamWriter will take more Resources. go test -run=none -bench=BenchmarkNewSheet -benchmem -count 10 name time/op name alloc/op name allocs/op |
|
l will Think about it, maybe I'll delete this api. |
FYI, here is a graph that shows the performance comparison of normal API and streaming writing API. I'll public testing code later. |
@xuri I have deleted that api. l was testing. l find |
Usually, the streaming API will use less memory and faster than normal API, but affected by business scenario, you need trade-off by yourself. Try profiling your program by |
@xuri so.when can merge PR ? |
/lgtm Thanks @Theodoree |
* optimize marshal * optimize mem alloc * add benchmark testing * add NewSheetWithRowNum testing * sync struct fields order * add BenchmarkNewSheetWithStreamWriter * delete NewSheetWithRowNum and benchmark test
* optimize marshal * optimize mem alloc * add benchmark testing * add NewSheetWithRowNum testing * sync struct fields order * add BenchmarkNewSheetWithStreamWriter * delete NewSheetWithRowNum and benchmark test
PR Details
1.align xlsxRow struct.
2.optimization workSheetWriter
3. add NewSheetWithRowNum
Description
Mainly to optimize memory allocation
Related Issue
l wish somebody can optimize xlsxC struct. it's too bigger.Maybe it can be optimized smaller.
Motivation and Context
sometime l use this package. memory will alloc 500m ~ 1000m. it's too expensive
How Has This Been Tested
Types of changes
Checklist