-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta
-
generic
-
generic
Name: yyT116575 Date: 11/06/2000
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Due to changes in java.awt.image.ComponentColorModel the programs that use
ColorSpace.TYPE_GRAY under certain circumstances execute at least Two Orders of
Magnitude slower when using jdk1.3 vs. jdk1.2
Here is the data:
mipl3{ozp}% uname -a
SunOS mipl3 5.7 Generic_106541-11 sun4u sparc SUNW,UltraAX-MP
mipl3{ozp}% java -version
java version "1.2.1"
Solaris VM (build Solaris_JDK_1.2.1_04, native threads, sunwjit)
% java Gray
Timing the operation from here:
Time Needed: 289ms
% /usr/java1.3/bin/java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0)
Java HotSpot(TM) Client VM (build 1.3.0, mixed mode)
% /usr/java1.3/bin/java Gray
Timing the operation from here:
Time Needed: 64023ms
The run time for the same program went from 289 ms to 64023 ms!!
That's a quarter of a second, to over a minute! Similar results
happen on Linux and Windows. Two orders of magnitude
slowdown in all three environments!
The test program is attached below.
Looking at the source code for ComponentColorModel in 1.2 vs. 1.3, somebody
COMMENTED OUT the TYPE_GRAY optimization!!! No reason is given for that
action. As a result, for grayscale images it goes through the entire ColorSpace
computation to get the color components, which is incredibly inefficient.
Here's a snippet from ComponentColorModel.getRed(Object) in 1.2:
else if (colorSpaceType == ColorSpace.TYPE_GRAY) {
return getGray(inData);
}
And the corresponding snippet from 1.3:
// REMIND: possible grayscale optimization here
// else if (colorSpaceType == ColorSpace.TYPE_GRAY) {
// return getGray(inData);
// }
Same changes have been done in getGreen(Object) and getBlue(Object)
Amazing, huh??
Here is the test program that has been used to diagnose and pinpoint the
problem:
-----------cut here-----------clip & save-----------valuable coupon-----------
import java.awt.*;
import java.awt.image.*;
public class Gray{
public static void main(String[] argv)
{
//Construct Gray scale BufferedImage
BufferedImage bufferedImage =
new BufferedImage(512, 512, BufferedImage.TYPE_BYTE_GRAY);
WritableRaster writableRaster = bufferedImage.getRaster();
ComponentColorModel componentColorModel =
(ComponentColorModel)bufferedImage.getColorModel();
System.out.println("Timing the operation from here: ");
long startTime = System.currentTimeMillis();
//Call getRed(Object object) for every pixel
for(int outer = 0; outer < 512; outer++)
for(int inner =0; inner < 512; inner++) {
Object object =
writableRaster.getDataElements(outer, inner, null);
//This call takes way longer in 1.3 in comparison to 1.2
componentColorModel.getRed(object);
}
System.out.println("Time Needed: "+(System.currentTimeMillis() - startTime) + "ms" );
}
}
(Review ID: 111805)
======================================================================
- relates to
-
JDK-4293698 Creating ComponentColorModel with Alpha causes long calc times
-
- Closed
-