https://bz.apache.org/bugzilla/show_bug.cgi?id=63234
Bug ID: 63234
Summary: XSSFFont.equals, hashCode very slow; revised code
presented
Product: POI
Version: 4.0.x-dev
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P2
Component: XSSF
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Created attachment 36475
--> https://bz.apache.org/bugzilla/attachment.cgi?id=36475&action=edit
XSSFFont.java revised to speed hashCode, toString, and equals by ~1000
I recently discovered that when writing Excel workbooks, 75% of my CPU time was
occupied by the method XSSFFont.equals.
I worked around this by the following:
1) Add instance fields _hashCode and _text to XSSFFont, initially set to null.
2) When either hashCode() or toString() are called and _hashCode==null, then
both _hashCode and _text are calculated and saved, and the value of _hashCode
or _text are returned.
3) Set the value of each of these fields to null whenever a setter (or
getCTFont) is called.
3) When equals is called, it uses the saved values of _hashCode and _text.
The result is significant speed improvement of more than x1000. The following
method calculates the time required to calculate font.equals(font), and the
time required to calculate font.oldEquals(font) (where oldEquals is the
original equals method). The results on my iMac are
equals: timePerCall=139 ns
oldEquals: timePerCall=216113 ns
The test code is below; my revised XSSFFont.java source is attached.
private static void testXSSFFontEquals(XSSFWorkbook workbook) {
final int numTests = 1000;
final XSSFFont font = workbook.getFontAt(0);
long start = System.nanoTime();
for (int n = 0; n < numTests; ++n) {
font.equals(font);
}
long end = System.nanoTime();
System.out.println(String.format("\r\nequals: timePerCall=%d
ns", (end - start) / numTests));
start = System.nanoTime();
for (int n = 0; n < numTests; ++n) {
font.oldEquals(font);
}
end = System.nanoTime();
System.out.println(String.format("oldEquals: timePerCall=%d
ns", (end - start) / numTests));
}
--
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]