JDK-4298749 : Slow repaint of JFrame/JLabel
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P1
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_7
  • CPU: sparc
  • Submitted: 1999-12-11
  • Updated: 2000-01-04
  • Resolved: 2000-01-04
Related Reports
Duplicate :  
Description
The attached program JFrame1.java creates 2000 JLabels, each with a 
blue background, in a JFrame, and then attempts to repaint the backgrounds 
of the JLabels alternately between orange and green every half second.

The bug is that the JLabels repaint very very slowly in JDK1.3. In 
JDK1.2.2 they repainted slowly, but now it is much much worse.  The
initial transition from blue to orange may take 18 minutes or longer.
It may then take 8 minutes or more to repaint them from orange to green and
green to orange.  If you don't wait that long, you may conclude it is
not repainting at all.

In JDK1.2.2 the initial transition from blue to orange took about 6 seconds
and the transitions between orange and green took about 3 seconds.

One problem contributing to this is that in
src/share/classes/javax/swing/RepaintManager.java
collectDirtyComponents spends a lot of time in the call to 'contains' 
calling 'indexOf' calling 'equals'.

  java.lang.Object.equals(Object.java)
  java.util.Vector.indexOf(Vector.java)
  java.util.Vector.contains(Vector.java)
  javax.swing.RepaintManager.collectDirtyComponents(RepaintManager.java)
  javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java)

This is because RepaintManager tries to figure out what needs to be
repainted as a result of the damage caused by repainting each
component. Since there are 2000 JLabels in this JFrame, this requires
at least 2000 squared comparisons. It might be more efficient to change
the logic so that if most of the JFrame needs to be repainted anyway,
then don't bother checking for the damage that repainting each
component causes, but rather repaint the whole frame, thereby avoiding
all the extra work.

For example, if the union of the bounding boxes of the components to be
repainted contains an area greater than 50% of the area of the JFrame,
then repaint the whole JFrame without checking for damage. Or if the JFrame
contains more than some large number of components, say 500, then repaint
the whole JFrame without checking for damage.

There must be multiple problems contributing to this bug, because even
with all this extra checking, it does not seem like it should take between
8 and 18 mimutes to repaint the JLabels.

mike.bronson@eng 1999-12-10

Comments
EVALUATION Is this only on solaris, or is it on Win32 as well? This looks like it could likely be related to bug ID# 4295241. This bug causes Object.wait() to timeout incorrectly, and I currently suspect it of causing all sorts of problems. Let's see if this bug is still there when 4295241 is integrated this build. steve.wilson@Eng 1999-12-11
11-12-1999