poi-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 53904] New: Generate xlsx File is slow causing by org.apache.poi.openxml4j.opc.PackageRelationshipCollection
Date Wed, 19 Sep 2012 14:42:42 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=53904

          Priority: P2
            Bug ID: 53904
          Assignee: dev@poi.apache.org
           Summary: Generate xlsx File is slow causing by
                    org.apache.poi.openxml4j.opc.PackageRelationshipCollec
                    tion
          Severity: critical
    Classification: Unclassified
                OS: All
          Reporter: superinkfish@gmail.com
          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: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Mime
View raw message