For me... your code results in:
5.000x100 cells: 11 seconds
10.000x100 cells: 28 seconds
20.000x100 cells
Out of memory errorThe clear memory increase was to be expected. DOM also uses lots of memory during buildup.
Question aside... I see you used the DOM nodes for the sheets... but what about the FSharedStrings??
In my example i only write strings to the cells (not numbers).
With this the FSharedStrings is being build up. (Numbers go directly in the sheet.xml and strings go to the SharedStrings.xml with a reference in the sheet.xml)
So if you're still using the FSharedString there is still some expensive string building going on.
(With a very large FSharedStrings, when using lots of string instead of numbers)
As a further note... Filling the DOM Nodes is expensive in time too. The two greatest advantages of using DOM is simplicity (for
reading/writing the nodes) and compatibility (not needing to care about XML). But in this case DOM is only being used for
writing. There is no need for reading the DOM nodes once they are written to memory. So one of the biggest advantages is not being used and only the compatibility (not caring about XML) remains.
But the biggest disadvantage is memory usage. So maybe this does not stand up against the advantage of compatibility.
So you could try (one more time) to include the FSharedStrings but otherwise it would be back to the drawing-board:
(considering the memory usage maybe that's best because in this case i couldn't even write 20.000 rows)
I do have some
other thoughts about
writing more efficiently:
In the other TsCustomSpreadWriter (like biff8 etc), all except xlsxooxml and fpsopendocument, i see there is a TMemoryStream being used. Why was this not used in the other two???
If TMemoryStream is more efficient and faster maybe that one should be used. (It would be easier to implement than the DOM Nodes.)
If it is faster there could also be a
switch added (very easily) to not use memory during writing. The TMemoryStream could be substituted for a TFileStream for example to write to temporary files so absolutely no memory would be used (just as an option).
Edit: Microsoft has a nice article about
"How To Improve String Concatenation Performance"