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

Optimize impl of snappedTopInset() methods in Region

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8
    • 8
    • javafx
    • None

    Description

      The 4 new methods added in RT-29805 only had simple implementations. They could benefit from caching the computed snapped insets in Region. The patch is pasted below:

      Running controls.bm.CheckboxBenchmark with 1400x1000px on Mac desktop I get

      32fps old impl
      34fps new impl

      so about 5% gain

      diff -r b4cfc5409461 javafx-ui-common/src/javafx/scene/layout/Region.java
      --- a/javafx-ui-common/src/javafx/scene/layout/Region.java Thu Apr 18 15:57:32 2013 -0700
      +++ b/javafx-ui-common/src/javafx/scene/layout/Region.java Thu Apr 18 17:14:23 2013 -0700
      @@ -353,6 +353,7 @@
               if (snapToPixel == null) {
                   if (_snapToPixel != value) {
                       _snapToPixel = value;
      + updateSnappedInsets();
                       requestParentLayout();
                   }
               } else {
      @@ -374,6 +375,7 @@
                           boolean value = get();
                           if (_snapToPixel != value) {
                               _snapToPixel = value;
      + updateSnappedInsets();
                               requestParentLayout();
                           }
                       }
      @@ -557,6 +559,7 @@
       
               void fireValueChanged() {
                   cache = null;
      + updateSnappedInsets();
                   requestLayout();
                   ExpressionHelper.fireValueChangedEvent(helper);
               }
      @@ -595,6 +598,31 @@
           };
       
           /**
      + * cached results of snapped insets, this are used a lot during layout so makes sense
      + * to keep fast access cached copies here.
      + */
      + private double snappedTopInset = 0;
      + private double snappedRightInset = 0;
      + private double snappedBottomInset = 0;
      + private double snappedLeftInset = 0;
      +
      + /** Called to update the cached snapped insets */
      + private void updateSnappedInsets() {
      + final Insets insets = getInsets();
      + if (_snapToPixel) {
      + snappedTopInset = Math.ceil(insets.getTop());
      + snappedRightInset = Math.ceil(insets.getRight());
      + snappedBottomInset = Math.ceil(insets.getBottom());
      + snappedLeftInset = Math.ceil(insets.getLeft());
      + } else {
      + snappedTopInset = insets.getTop();
      + snappedRightInset = insets.getRight();
      + snappedBottomInset = insets.getBottom();
      + snappedLeftInset = insets.getLeft();
      + }
      + }
      +
      + /**
           * The width of this resizable node. This property is set by the region's parent
           * during layout and may not be set by the application. If an application
           * needs to explicitly control the size of a region, it should override its
      @@ -1362,8 +1390,8 @@
            * @since 8.0
            * @return Rounded up insets top
            */
      - public final int snappedTopInset() {
      - return (int)snapSize(getInsets().getTop());
      + public final double snappedTopInset() {
      + return snappedTopInset;
           }
       
           /**
      @@ -1373,8 +1401,8 @@
            * @since 8.0
            * @return Rounded up insets bottom
            */
      - public final int snappedBottomInset() {
      - return (int)snapSize(getInsets().getBottom());
      + public final double snappedBottomInset() {
      + return snappedBottomInset;
           }
       
           /**
      @@ -1384,8 +1412,8 @@
            * @since 8.0
            * @return Rounded up insets left
            */
      - public final int snappedLeftInset() {
      - return (int)snapSize(getInsets().getLeft());
      + public final double snappedLeftInset() {
      + return snappedLeftInset;
           }
       
           /**
      @@ -1395,8 +1423,8 @@
            * @since 8.0
            * @return Rounded up insets right
            */
      - public final int snappedRightInset() {
      - return (int)snapSize(getInsets().getRight());
      + public final double snappedRightInset() {
      + return snappedRightInset;
           }

      Attachments

        Activity

          People

            jasper Jasper Potts (Inactive)
            jasper Jasper Potts (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported: