Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

performance - Slow Java2D bilinear interpolation in Java 7 on Mac OS X

I've been testing my app in Java 7 on Mac OS X. It's running noticeable sluggish. I used VisualVM to try and track down where the bottleneck was and found linear interpolation to be the culprit:

g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

To some degree this makes sense of course. Using interpolation will slow things down. But I do not see this kind of dramatic difference between using and not using interpolation in Java 6 on OS X. In Java 6, the difference was almost negligible. (The images below represent the VisualVM profile of paintComponent() after running through a standard animation in my app.)

With interpolation:

enter image description here

Without interpolation:

enter image description here

But in Java 7 on OS X, the difference is much more noticeable:

With interpolation:

enter image description here

Without interpolation:

enter image description here

I'm guessing the issue lies in hardware acceleration and the transition from Apple to Oracle. Perhaps Apple's Java 6 was using hardware acceleration to do the interpolation and now Oracle's Java 7 is not. Does this explain it? Is there a solution? I've tried sun.java2d.opengl=true.

Update: I found that the issue only appears when using setRenderingHints() to apply interpolation. If you use another method to interpolate the image, such as AffineTransformOp, then the performance drop disappears. For example:

g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
AffineTransformOp scaleOp = new AffineTransformOp(scaleTransform, AffineTransformOp.TYPE_BILINEAR);
scaleOp.filter(screenSliceFiltered, screenSliceFilteredScaled);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I think you've hit the nail on the head. In all likelihood the Apple provided JVM leveraged hardware acceleration. You might ask over on the Porters group mailing list of the Mac Port sub-project of OpenJDK.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...