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

Performance improvement in class javax.swing.text.BoxView

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 5.0
    • client-libs

      A DESCRIPTION OF THE REQUEST :
      There is a considerable potential for performance improvement in class javax.swing.text.BoxView and its subclasses (FlowView, ParagraphView, BlockView, ListView, TableView etc.).

      The methods calculateMajorAxisRequirements(...) and calculateMinorAxisRequirements(...) do more calculations than necessary in many cases. Both methods are called often for layout of the view structure. Currently they _always_ calculate the minor, major, and preferred span of the child views. In cases where the child views are not resizable (in other words: minor, major, and preferred span are the same), calculating the minor and major span of a child is just a waste of time, only calculating the preferred span should be enough. Checking if a child is resizable can be done by calling its getResizeWeight() method (if the return value is zero, the view is not resizable), which is done in many other cases (for example in method baselineLayout(...) in class BoxView). But in the two mentioned methods this has not been done yet.

      JUSTIFICATION :
      The javax.swing.text package has a reputation of being rather sluggish, so performance improvements are desirable. The class BoxView is a widely used class with many subclasses, which means the performance will be improved in many cases.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A high perfomance of the javax.swing.text package, without any changes in the actual behaviour.
      ACTUAL -
      Performance of the javax.swing.text package has potential for performance improvements.

      ---------- BEGIN SOURCE ----------
      Difficult to implement, but I hope that the expert for the text package sees that this is an easy performance improvement.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Below is the modified source code of the methods calculateMajorAxisRequirements(...) and calculateMinorAxisRequirements(...) that implements the performance improvements. This is not a workaround, but a patch for the current BoxView implementation.


      protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
      // calculate tiled request
      float min = 0;
      float pref = 0;
      float max = 0;

      int n = getViewCount();
      for (int i = 0; i < n; i++) {
      View v = getView(i);
            float childPrefSpan = v.getPreferredSpan(axis);
            pref += childPrefSpan;
      if (v.getResizeWeight(axis) == 0) {
              min += childPrefSpan;
              max += childPrefSpan;
            } else {
              min += v.getMinimumSpan(axis);
              max += v.getMaximumSpan(axis);
            }
      }

      if (r == null) {
      r = new SizeRequirements();
      }
      r.alignment = 0.5f;
      r.minimum = (int) min;
      r.preferred = (int) pref;
      r.maximum = (int) max;
      return r;
          }


        protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
      int min = 0;
      long pref = 0;
      int max = Integer.MAX_VALUE;
      int n = getViewCount();
      for (int i = 0; i < n; i++) {
      View v = getView(i);
            float childPrefSpan = v.getPreferredSpan(axis);
            pref = Math.max((int) childPrefSpan, pref);
      if (v.getResizeWeight(axis) == 0) {
              min = Math.max((int) childPrefSpan, min);
      max = Math.max((int) childPrefSpan, max);
            } else {
              min = Math.max((int) v.getMinimumSpan(axis), min);
      max = Math.max((int) v.getMaximumSpan(axis), max);
            }
      }

      if (r == null) {
      r = new SizeRequirements();
      r.alignment = 0.5f;
      }
      r.preferred = (int) pref;
      r.minimum = min;
      r.maximum = max;
      return r;
          }
      ###@###.### 2005-03-02 01:10:11 GMT

            peterz Peter Zhelezniakov
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: