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

Property values shouldn't be requested more than once per frame

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u20
    • javafx

      When trying to optimize JavaFX code for performance one may try to use bindings to avoid calculations to be done multiple times because several dependencies where modified during the frame.

      Here is the example:

      circle.fillProperty().bind(Bindings.createObjectBinding(() -> performExpensiveCalculation(), property1, property2, propert3);

      which has circle.fillProperty to be defined as the expensive calculation of a three incoming properties, numbered 1 through 3.

      By the contract, this statement means that value is only calculated once when needed, even if there were several changes to depended properties. For example, all three were changed and one was changed more than once. Even in that case, performExpensiveCalculation() should be only called when the value is actually requested. In this case one may assume it is done when frame is rendered onto a screen.

      However, if you look inside the source code, fillProperty instantiates an object, that calls get() each time whenever the property is invalidated. Thus, the expensive calculation will be invoked at least once per each dependency invalidation, many times per frame.

      This hurts performance and contradicts with properties and bindings contract.

      I'm encouraging developers to look through all the properties in the platform to make sure they're not doing get() in invalidated() method.

            Unassigned Unassigned
            mrkam Alexander Kuznetcov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Imported: