Skip to content

Consider using SXSSWorkbook for reading xlsx files #1016

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

Closed
koperagen opened this issue Jan 17, 2025 · 1 comment · Fixed by #1075
Closed

Consider using SXSSWorkbook for reading xlsx files #1016

koperagen opened this issue Jan 17, 2025 · 1 comment · Fixed by #1075
Assignees
Labels
files reading/writing from/to files help wanted Extra attention is needed, feel free to help :)

Comments

@koperagen
Copy link
Collaborator

koperagen commented Jan 17, 2025

xssfworkbook keeps whole file in memory, which for even relatively small dataframes or 100k rows can lead to a very significant memory consumption. sxssfworkbook implements streaming writing and flushes rows on disk as you write them. For comparison, max heap writing dataFrameOf('a'..'z').fill(1_000_000) { it }:
xssfworkbook 15 gb
sxssfworkbook 1.6 gb

The only concern is some potential incompatibilities mentioned in javadoc here:
https://poi.apache.org/apidocs/dev/org/apache/poi/xssf/streaming/SXSSFWorkbook.html

Other than that, from user perspective df.writeExcel(file) will benefit from much smaller memory consumption without lose of functionality:
https://poi.apache.org/components/spreadsheet/
https://stackoverflow.com/questions/33047512/hssfworkbook-vs-xssfworkbook-vs-sxssfworkbook-apache-poi

Check some other JVM DF libraries, do they use it?

@koperagen koperagen added files reading/writing from/to files help wanted Extra attention is needed, feel free to help :) labels Jan 17, 2025
@koperagen koperagen modified the milestones: Backlog, 0.16.0 Jan 17, 2025
@koperagen
Copy link
Collaborator Author

https://github.com/dhatim/fastexcel

Its streaming API may mitigate this problem but it introduces several limitations:

Its sliding window mechanism prevents you from accessing cells above the current writing position.
It writes stuff to a temporary file.
It comes with an overhead on the file size because shared strings are disabled by default. Enabling shared strings is likely to consume much more heap if you deal with string values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
files reading/writing from/to files help wanted Extra attention is needed, feel free to help :)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants