I need to create many Excel files in a batch. I use a common template and populate with different data and then write out the file to an IOBuffer()
using XLSX.jl. This remains slower than I expected, even after this PR was merged.
When I try
xio = IOBuffer()
@time XLSX.writexlsx(xio, template)
inside a loop over all datasets, I get (for example)
...
0.474708 seconds (6.47 k allocations: 1.295 MiB, 97.73% gc time)
0.471064 seconds (6.45 k allocations: 1.269 MiB, 97.48% gc time)
0.449121 seconds (6.45 k allocations: 1.269 MiB, 96.74% gc time)
0.433755 seconds (6.45 k allocations: 1.269 MiB, 97.53% gc time)
0.447344 seconds (6.46 k allocations: 1.295 MiB, 97.79% gc time)
0.473887 seconds (6.46 k allocations: 1.270 MiB, 97.99% gc time)
0.440383 seconds (6.47 k allocations: 1.270 MiB, 97.83% gc time)
...
Iβve had a go at basic profiling to try to see what is going on:
Profile - Click to expand
Overhead β [+additional indent] Count File:Line; Function
=========================================================
β279 @Base\client.jl:552; _start()
β 279 @Base\client.jl:318; exec_options(opts::Base.JLOptions)
β 279 @Base\Base.jl:495; include(mod::Module, _path::String)
β 279 @Base\loading.jl:2136; _include(mapexpr::Function, mod::Module, _path::String)
β 279 @Base\loading.jl:2076; include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
β 279 @Base\boot.jl:385; eval
β β 279 @VSCodeDebugger\src\VSCodeDebugger.jl:45; startdebugger()
β β 279 @DebugAdapter\src\packagedef.jl:122; run(debug_session::VSCodeDebugger.DebugAdapter.DebugSession, error_handler::VSCodeDebugger.var"#3#4"{String})
β β 279 @Base\client.jl:489; include(fname::String)
β β 279 @Base\loading.jl:2136; _include(mapexpr::Function, mod::Module, _path::String)
β β 279 @Base\loading.jl:2076; include_string(mapexpr::typeof(identity), mod::Module, code::String, filename::String)
β β β 279 @Base\boot.jl:385; eval
β β β 279 β¦ood Cause Summaries Team - General\Good Cause Summaries\Code\ChooseBatches.jl:47; chooseBatches()
β β β 279 @Base\timing.jl:279; macro expansion
β β β 279 β¦ Team - General\Good Cause Summaries\Code\Template-jl-Library\lib-batches.jl:88; ProcessAllBatches(BatchFolders::DataFrame)
β β β 279 β¦ Team - General\Good Cause Summaries\Code\Template-jl-Library\lib-batches.jl:68; ProcessBatch(dir::String, dcms::DataFrame, remgrants::DataFrame)
β β β β 279 @Base\timing.jl:279; macro expansion
β β β β 279 β¦s Team - General\Good Cause Summaries\Code\Template-jl-Library\lib-write.jl:144; writeTemplates(summaries::DataFrame, logIO::IOBuffer)
β β β β 279 @Profile\src\Profile.jl:44; macro expansion
β β β β 279 β¦ Team - General\Good Cause Summaries\Code\Template-jl-Library\lib-write.jl:142; (::var"#x#67"{XLSX.XLSXFile})()
β β β β 279 @XLSX\src\write.jl:52; writexlsx(output_source::IOBuffer, xf::XLSX.XLSXFile)
β β β β β 2 @XLSX\src\write.jl:61; writexlsx(output_source::IOBuffer, xf::XLSX.XLSXFile; overwrite::Bool)
β β β β β 1 @XLSX\src\write.jl:172; update_worksheets_xml!(xl::XLSX.XLSXFile)
β β β β β 1 @EzXML\src\xpath.jl:79; findall(xpath::String, node::EzXML.Node, ns::Vector{Pair{String, String}})
β β β β β 1 @EzXML\src\xpath.jl:136; new_xpath_context
1β β β β β 1 @XLSX\src\write.jl:233; update_worksheets_xml!(xl::XLSX.XLSXFile)
β β β β β 2 @XLSX\src\write.jl:63; writexlsx(output_source::IOBuffer, xf::XLSX.XLSXFile; overwrite::Bool)
β β β β β 2 @ZipArchives\src\writer.jl:52; ZipWriter
β β β β β 2 @ZipArchives\src\writer.jl:55; ZipWriter(f::XLSX.var"#44#45"{XLSX.XLSXFile}, io::IOBuffer; zip_kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}})
β β β β β 1 @XLSX\src\write.jl:72; (::XLSX.var"#44#45"{XLSX.XLSXFile})(xlsx::ZipWriter{IOBuffer})
β β β β β 1 @EzXML\src\document.jl:60; print
β β β β β β 1 @EzXML\src\node.jl:310; print
β β β β β β 1 @EzXML\src\node.jl:340; dump_node(io::ZipWriter{IOBuffer}, node::EzXML.Node, format::Bool)
β β β β β β 1 @Base\strings\io.jl:250; print
β β β β β β 1 @Base\strings\io.jl:248; write
β β β β β β 1 @ZipArchives\src\writer.jl:307; unsafe_write(w::ZipWriter{IOBuffer}, p::Ptr{UInt8}, n::UInt64)
1β β β β β β β 1 @ZipArchives\src\reader.jl:2; unsafe_crc32
β β β β β 1 @XLSX\src\write.jl:77; (::XLSX.var"#44#45"{XLSX.XLSXFile})(xlsx::ZipWriter{IOBuffer})
β β β β β 1 @ZipArchives\src\writer.jl:169; zip_newfile
β β β β β β 1 @ZipArchives\src\writer.jl:178; zip_newfile(w::ZipWriter{IOBuffer}, name::String; comment::String, compress::Bool, compression_method::UInt16, compression_level::Int64, executable::Nothing, extβ¦
β β β β β β 1 @ZipArchives\src\writer.jl:334; zip_commitfile(w::ZipWriter{IOBuffer})
β β β β β β 1 @TranscodingStreams\src\stream.jl:524; write
β β β β β β 1 @TranscodingStreams\src\stream.jl:642; flush_buffer1(stream::TranscodingStreams.TranscodingStream{CodecZlib.DeflateCompressor, ZipArchives.WriteOffsetTracker{IOBuffer}})
β β β β β β 1 @TranscodingStreams\src\stream.jl:685; callprocess(stream::TranscodingStreams.TranscodingStream{CodecZlib.DeflateCompressor, ZipArchives.WriteOffsetTracker{IOBuffer}}, inbuf::TranscodingStrβ¦
β β β β β β β 1 @CodecZlib\src\compression.jl:177; process(codec::CodecZlib.DeflateCompressor, input::TranscodingStreams.Memory, output::TranscodingStreams.Memory, error::TranscodingStreams.Error)
1β β β β β β β 1 @CodecZlib\src\libz.jl:77; deflate!
β β β β β 275 @XLSX\src\write.jl:87; writexlsx(output_source::IOBuffer, xf::XLSX.XLSXFile; overwrite::Bool)
β β β β β 275 @Base\gcutils.jl:129; gc
275β β β β β 275 @Base\gcutils.jl:129; gc
Total snapshots: 279. Utilization: 100% across all threads and tasks. Use the `groupby` kwarg to break down by thread and/or task.
Looking at line 87 in write.jl
:
# fix libuv issue on windows (#42)
@static Sys.iswindows() ? GC.gc() : nothing
So I have several questions:
- What is
libuv
and what is thelibuv
issue? How is the issue manifested inwritexlsx.jl
- in other words what might the consequences be if I deleted this line? - Are there plans to fix the
libuv
issue or is there a way to work around it? Has it perhaps already been fixed? (Issue #42 is closed) - Rejected PR #270 wanted to remove the related gc call from
read.jl
. Is it safe to do the same fromwrite.jl
?
Thanks for any help you can offer!