https://bz.apache.org/bugzilla/show_bug.cgi?id=63774

            Bug ID: 63774
           Summary: Custom properties "add" method is slow
           Product: POI
           Version: 4.0.0-FINAL
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: dev@poi.apache.org
          Reporter: serhiy.boyche...@cern.ch
  Target Milestone: ---

Dear developers,

We have recently experienced an issue moving to the latest release. In one of
our use cases we are setting a large number of custom properties to an Excel
(XLSX) file and it seems that in recent versions something was changed and this
process became much slower. Consider the following code:


public class PoiTest {
    public static void main(String[] args) throws IOException {
        try (FileInputStream fis = new FileInputStream("test.xlsx")) {
            XSSFWorkbook workbook = new XSSFWorkbook(fis);

            POIXMLProperties.CustomProperties properties =
workbook.getProperties().getCustomProperties();

            IntStream.range(0, 10000).forEach(i -> {
                long ts = System.currentTimeMillis();
                properties.addProperty("property" + i, "value" + 1);
                System.out.println(i + " time taken " +
(System.currentTimeMillis() - ts));
            });
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

You will see that time is constantly increasing. The investigation led me to
conclude that the cause is the call to 'nextPid()' method in 'CustomProperties'
class (defined in 'POIXMLProperties'). If you notice, every time the method is
called, it iterates over the whole structure to find out which is the latest
pid. In our case, since we do the changes sequentially, we have implemented a
workaround in our code base to cache pid, in more general case I am not sure
what should be a solution (if any), but performance after some point
deteriorates so much that it makes application unusable.

Best regards,
Serhiy.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@poi.apache.org
For additional commands, e-mail: dev-h...@poi.apache.org

Reply via email to