Archive

Posts Tagged ‘runtime’

JavaFX – FPS Meter

November 9, 2009 5 comments

One of my previous post mentioned about way to specify Z-Order for JavaFX Nodes. Just thought of putting this approach to use in a carousel. There are lots of interesting samples available at shinedraw.com – Flash vs Silverlight Repository. Below is JavaFX port of FPS-Meter..





To launch click on above image or Click to add more images.

Note: The icons used in this sample are from MouseRunner.com licensed under the Attribution-ShareAlike 3.0 Unported.

I did some monitoring with JConsole. It was giving consistent 60 fps for 50 nodes with average 13% CPU usage. JConsole details available here. I’ll leave it to experts to come up with proper conclusion…

Launch JavaFX FPS Meter. Start JConsole and select the process
com.sun.javafx.runtime.Main javafxfpsmeter.Main
from “Local Process” list.

System Information:

  • JavaFX: 1.2.1 (public)
  • JavaSE: 1.6.0_16
  • OS: Windows Vista
  • Processor: Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz
  • Memory (RAM): 1.00 GB
  • Display: NVIDIA Quadro NVS

There is significant performance improvement done in different components of JavaFX for next release.. Stay tuned.. I will share the statistics with exactly same test and same system so as to compare the improvement..

Please try it out and share your information and thoughts..

var dzone_style = ‘2’;

Categories: javafx Tags: , ,

JavaFX – Bind with Caution!

July 7, 2009 4 comments

JavaFX “bind” and “on replace” are really nice and useful features. But recently I came across many misuse of this feature which results in performance issues. Here we will look into couple of common usage which leads to performance issues..

An example application is shown below…

For Applet mode, click on above image

For standalone mode

Example: In below code, the user wants to perform “update” operation when ever there is any change in x, y, w and height. The initial values of these variables are set to 0. Later as and when the application is shown on screen, actual values of these are updated.


var x = on replace update()}
var y = on replace update()}
var width = on replace update()}
var height = on replace update()}

function update() {
    /**
     * Performs complex update process!
     */
}

But during this process, the “update” method is invoked 8 times! 4 times when the variable is initialized to 0 and another 4 times when the actual value is set. Instead if we perform a simple check to ensure that all variables are set before update, we could have easily avoided performing the complex operation so many times and improve performance.


function update() {
    if((x > 0and (y > 0and (width > 0and (height > 0)) {
        /**
         * Performs complex update process!
         */
    }
}

Another common usage is binding to value of Slider or ScrollBar. Objective is to perform some operation as and when the value is updated by user.


var slider = Slider {
    min: 0
    max: 100
    value: 50
}

var sliderValue = bind slider.value on replace {
    /**
     * Perform Complex Operation!!!!
     */
}

But this will end up performing the operation many many times before the actual value required by user is set. Also the slider won’t be responsive, since we are constantly repeating the task. So instead of performing operation for each and every value with in the interval, we may just wait for few milli-seconds before performing the actual operation.


var slider = Slider {
    min: 0
    max: 100
    value: 50
}

var timeline = Timeline {
    keyFrames: KeyFrame {
        time: 50ms
        action: function() {
            /**
             * Perform Complex Operation!!!!
             */
        }
    }
}

var sliderValue = bind slider.value on replace {
    timeline.playFromStart();
}

In above code a Timeline is started when ever the user changes the slider value. The actual operation is performed only after few (50ms in above code) milli-seconds. This will ensure that we won’t perform complex operation until user settles for a value.

Also bind is used for layout of nodes along with boundsInLocal, boundsInParent etc. Instead try to use various layouts such as Flow, HBox, Panel, Stack, Tile, VBox and LayoutInfo.

Also refer to Girish’s blog which talks about another common performance issue related to dynamic update of nodes.

These are not the only issues or only solutions, the objective is to just caution the usage, so that you can optimize the code as per your requirement. Try it out and let me know feedback

Source:

var dzone_url = “http://blogs.sun.com/rakeshmenonp/entry/javafx_bind_with_caution”;
var dzone_style = ‘2’;

Categories: javafx Tags: , ,