jferard / fastods

A very fast and lightweight (no dependency) library for creating ODS (Open Document Spreadsheet, mainly for Calc) files in Java. It's a Martin Schulz's SimpleODS fork
GNU General Public License v3.0
36 stars 6 forks source link

Threading #33

Closed jferard closed 7 years ago

jferard commented 7 years ago

Reminder:

Now, under some assumptions, it is possible to split FastODS work into two threads:

These assumptions are:

I think there is only one way to discover if it will really speed up the file creation: try!

jferard commented 7 years ago

The currrent design doesn't fit to threading.

The process is quite strict: the data is written at the very end of the process. All the objects (tables, rows, cells, styles) are first created by the user, then transcripted to XML format and written to the file.

The aim is to make the process more flexible, allowing to flush data at any time, but to keep the current behavior in the case of a single flush at the end.

Here's a possible kind of "producer-consumer" design:

Note 1: all the files of the ods archive, except content.xml, must be written before content.xml. That means that the styles have to be inserted manually in the document.

Note 2: this would free some memory, if the rows are set to null in the document when sent to the bus.

jferard commented 7 years ago

This is the most hard feature to implement for 0.3.0, so this issue will be the first in the next iteration. I think now that the point is not speed but memory: a flush method would allow to free memory fast, e.g. after each table is complete.

The flush should be a method from OdsFileWriter:

jferard commented 7 years ago

Here are a few steps:

jferard commented 7 years ago
jferard commented 7 years ago

The current implementation is very tedious:

The goal is:

  1. the user chooses a number of lines in the "buffer";
  2. when the lines are filled with data, the flush method is automatically called.
  3. if a new style appears after the first flush, an error is sent to log.
jferard commented 7 years ago

This seems to be a too big step for one iteration. Let"s split it in two:

  1. First step: create a flushable OdsFileWriter that reproduces the OdsDocument output;
  2. Split the job into two threads: the first thread writes objects; the second thread writes a file.

I keep this issue open, but set to milestone 3.1, and open a new issue for the first step.

jferard commented 7 years ago

The current implementation of the flushmethod misses the point: the first thread should handle the whole text/xml production (including escape of xml chars), the second thread the writing of the text/xml into the output stream. The communication using one or several CharBuffer seems a good solution.

Let's split this issue into two new issues:

jferard commented 7 years ago

See #69