Hi,
I have pasted a screen shot of CPU profiling for JasperReports. The report
takes about 9 seconds to generate, 0.5 seconds of that is spent
instantiating PdfGraphics2D.
http://i.imgur.com/arzCI.png
Briefly, I noticed a few things:
1. No lazy initialization is being used.
2. Two instances of AffineTransform() are created (IDENTITY constant and
one in the constructor).
3. Redundant instance variable assignments to false.
4. The logic "if (this.fontMapper == null)" seems redundant (it's the
constructor, so the fontMapper will be null?).
5. There is code duplication in the constructor that takes many
arguments; I'd recommend moving the common code out into its own method.
6. strokeOne should be a final constant (it is never assigned).
It can be a bit more efficient to access a local variable than a class scope
variable. (This has many OO advantages, too.) For example, the following
code runs slowly:
public class T {
private long x;
public T() {}
public void run() {
//long xl = getX();
for( int i = 0; i < 100000; i++ ) {
for( int j = 0; j < 100000; j++ ) {
//xl = i * j;
x = i * j;
}
}
//setX( xl );
}
public long getX() { return this.x; }
private void setX( long x ) { this.x = x; }
public static void main( String args[] ) {
T t = new T();
t.run();
}
}
If you change the code around to use an instance variable (by uncommenting
the commented lines and making the appropriate change in the inner loop),
you'll see at least an order of magnitude increase in speed. (This is
because the JVM uses a longer bytecode to address a class variable than it
does a local scope variable; I don't think the JIT will optimize it.)
The doAttributes() method, for example, will suffer a little because of
this.
Dave
------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/