Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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);
like image 512
martinez314 Avatar asked Apr 18 '26 04:04

martinez314


1 Answers

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.

like image 85
brettw Avatar answered Apr 20 '26 16:04

brettw



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!