load_workbook slow on files with many custom styles
Created originally on Bitbucket by Alberto Donizetti
I'm using openpyxl 2.6.2 to process .xlsx files that come with a huge
number of custom styles (styles.xml is >9MB uncompressed).
On an otherwise empty xlsx file, load_workbook takes 15s of walltime
to execute, even in read_only mode:
import openpyxl
%time wb = openpyxl.load_workbook('test.xlsx', read_only=True)
CPU times: user 12.8 s, sys: 265 ms, total: 13.1 s
Wall time: 14.3 s
I know it's the styles because if I pre-process the file to remove the
custom styles with this VB script:
Sub StyleKiller()
Dim N As Long, i As Long
With ActiveWorkbook
N = .Styles.Count
For i = N To 1 Step -1
If Not .Styles(i).BuiltIn Then .Styles(i).Delete
Next i
End With
End Sub
it loads in a few milliseconds.
I've read the conversation on Issue #733. The patch there certainly
mitigated the issue, but sadly load_workbook still takes >95% of the
walltime in my pipeline.
I see that the idea of ignoring named styles in read_only mode was
thrown around in that thread. If that's actually possible, that would
be great, as it would make load_workbook two orders of magnitude
faster on the files I'm processing.
P.S. attached .xlsx file can be used to reproduce the issue
Attachments: test.xlsx