Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4293264

ToolTipManager causes serious hit in perfomance (getToolTipText)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0, 1.3.1
    • client-libs
    • beta
    • generic, x86
    • generic, linux, windows_98



      Name: mc57594 Date: 11/21/99


      description : java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Java(TM) HotSpot Client VM (build 1.3beta-O-release, 1.3beta-O-release,
      interpreted mode)

      also

      java version "1.2.2"
      Classic VM (build JDK-1.2.2-U, green threads, sunwjit)
      (repost of Review ID:97011)

      > The ToolTipManager is calling getToolTipText() way too many times....on every
      > mouse move....even when it does not intend to pop up a tool tip (tip disabled
      > or no tool-tip text set).
      >
      > This can cause serious performance hits if the implementation of
      > getToolTipText() is expensive:
      >
      > 1. In JTable, this causes prepareRenderer(), getValueAt() and getRowCount(),
      > etc. to be called on *every* mouse move. When JTable is coupled
      > w/ other models or UIs (like JTree), this can use ALOT of resources.
      >
      > 2. In a generic drawing tool, where there's only one JComponent (the
      canvas),
      > and we're managing the objects drawn on the canvas, each mouse move
      > causes us to search the entire object hierarchy to find the graphic
      > closest to the cursor for the proper tool-tip. This can be very
      > expensive if there are alot of objects, or the hierarchy is deep.
      >
      > In both these cases (and more?), there's no reason for the ToolTipManager to
      > call getToolTipText() until it's about to pop up the tipWindow instead of
      every
      > mouse move. Since it has all the smarts/timing algorithms, etc, that should
      be
      > possible.

      The settings:

      1. setDismissDelay(...)
      2. setReshowDelay(...)
      3. setInitialDelay(...)

      have no effect on this behavior. The getToolTipText() calls
      are happening on every mouse move, regardless of these settings.
      That's what makes the existing implementation of ToolTipManager.java
      so "dangerous", because it provides a false sense of security.

      Yes, this behavior still exists in 1.3beta.

      Code to reproduce:

      ------------------------ Bug.java ------------------------------

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.JButton;
      import javax.swing.JTable;
      import javax.swing.JScrollPane;
      import javax.swing.table.TableModel;
      import javax.swing.table.AbstractTableModel;

      public class Bug extends JFrame implements ActionListener
      {
          private static int NCOLS = 3;
          private static int NROWS = 30000;

          private JButton _add;
          private JButton _close;
          private TableModel _dataModel;
          private JTable _table;
          private JScrollPane _tableScroll;

          public Bug()
          {
              JPanel p = new JPanel();
              _add = new JButton("Add");
              _add.addActionListener(this);
              p.add(_add);
              _close = new JButton("Close");
              _close.addActionListener(this);
              p.add(_close);
              getContentPane().add(p, BorderLayout.SOUTH);

              _dataModel = new AbstractTableModel() {
                      public int getColumnCount() {
                          System.out.println("Cols");
                          return NCOLS;
                      }
                      public int getRowCount() {
                          System.out.println("Rows");
                          return NROWS;
                      }
                      public Object getValueAt(int row, int col) {
                          System.out.println("++ (" + row + ", " + col + ")");
                          if (row == 42) { Thread.dumpStack(); }
                          return new Integer(row*col);
                      }
                  };
              _table = new JTable(_dataModel);
              _tableScroll = new JScrollPane(_table);

              getContentPane().add(_tableScroll, BorderLayout.CENTER);
              pack();
          }

          public void actionPerformed(ActionEvent e)
          {
              Object src = e.getSource();
              if (src == _add) {
                  // do nothing
              } else if (src == _close) {
                  System.exit(0);
              }
          }

          public static void main(String args[])
          {
              Bug w = new Bug();
              w.show();
          }
      }

       ------------------------ To compile and run -------------------------
      javac Bug.java
      java Bug

      ---------------------- What to do to see problem ----------------------

      Move mouse over the JTable and see that you get output like:
      Rows
      ++ (10, 1)
      Rows
      ++ (13, 1)
      Rows
      ++ (16, 1)
      Rows
      ++ (17, 1)
      Rows
      ++ (17, 1)
      Rows
      ++ (18, 1)
      Rows
      ++ (18, 1)
      Rows
      ++ (18, 1)
      Rows
      ++ (20, 1)
      Rows
      ++ (21, 1)
      Rows
      ++ (22, 1)

      and if you go down the the row where the second colum reads "42", you'll
      get a stack dump.

      Note that in this example, the ToolTips are NOT on (You can even run
      setEnabled(false)),
      but the ToolTipManager still calls getToolTipText() for every mouse move.....

      Hope this is enough details.
      (Review ID: 97340)
      ======================================================================

            svioletsunw Scott Violet (Inactive)
            mchamnessunw Mark Chamness (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: