https://issues.apache.org/bugzilla/show_bug.cgi?id=53904

          Priority: P2
            Bug ID: 53904
          Assignee: [email protected]
           Summary: Generate xlsx File is slow causing by
                    org.apache.poi.openxml4j.opc.PackageRelationshipCollec
                    tion
          Severity: critical
    Classification: Unclassified
                OS: All
          Reporter: [email protected]
          Hardware: All
            Status: NEW
           Version: 3.8
         Component: XSSF
           Product: POI

When I generate a xlsx file which size is 1.7MB, I wait more than 11 minutes to
finish. When I fix the bug, the time is reduce to 5 seconds.
My code(JDK 1.7):
try (BufferedOutputStream out = new
BufferedOutputStream(desFile.getContent().getOutputStream())) {
            this.workbook.write(out);
} catch (IOException ex) {
    log.error(ex.getMessage(), ex);
}

The bug(org.apache.poi.openxml4j.opc.PackageRelationshipCollection):
public PackageRelationship addRelationship(URI targetUri, TargetMode
targetMode, String relationshipType, String id) {
    if (id == null) {
        // Generate a unique ID is id parameter is null.
        int i = 0;
        do {
            id = "rId" + ++i;
        } while (relationshipsByID.get(id) != null);
    }
    ......
}
The variable i will raise form 0 to 1000000 when the method be called  1000000
and the loop will calculate more than 500000 billion times!

I modified the code:
private int currentRelationshipsId = 0;
public PackageRelationship addRelationship(URI targetUri, TargetMode
targetMode,
 String relationshipType, String id) {
    if (id == null) {
        // Generate a unique ID is id parameter is null.
        id = "rId" + ++currentRelationshipsId;
    }
    ......
}

The performance became more faster.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to