Tuesday Feb 23, 2010

JavaFX - Performance Optimization

There was a question related to Best Practices for speed optimization in Oracle-Mix forum. There are many small tips & tricks, just thought of listing out what ever came to my mind..

Use Layout: For positioning node always use Layout. There are plenty of layout available such as HBox, VBox, Tile, Flow and Stack. If we need any custom layout you can use Container or Panel. Position node using layoutX and layoutY attributes. Use translateX and translateY for Animation.

Consolidate Theme Attributes : We can reuse many theme related objects such as Font, Color, Paint, Image. Eg: If we use same Font for many Label/Text, we can use the same Font instance instead of creating one each for each instance of Node. This consolidation also allow us to customize the UI. You may refer to Theme used in Calendar sample. Also share Image instances such as default-image, place-holder image etc across multiple objects.

Bind with Caution: I have stressed on this in one of my previous post. Repeating the same again. Use this mostly for wiring model to view. Minimize use for other purpose such as layout of Nodes. Also better to avoid chaining of binds, its very problematic and difficult to debug.

JavaFX for View: There is a tendency to write entire application using pure JavaFX. This may be fine for small widget like application or samples. But when you write real business application we need to push out the business logic, IO operations and non-ui related code to Java layer. Use JavaFX Async APIs + Callback methods so as to execute these code outside Event-Dispatch-Thread. HttpRequest API demonstrates use of this approach.

Reduce use of Effects: In many cases we may need to have static effects in UI, such as nice gradient for background, font effects etc. If these effects are static, its always better to use Image instead of effect API.

Stroke Vs Fill: Instead of using stroke attribute for shape, we may use nested shapes with fill attribute. Example: For creating a stroke for Rectangle, we can create two instances of Rectangle overlapping, with the inner Rectangle smaller than outer Rectangle. This will have better performance compared to use of stroke attribute.

Avoid Class-Path in Manifest: When we add various jars as library to Netbeans, these jars are directly referenced in Class-Path of Manifest file of the application jar. When deployed, this will force to download all jars before start of application. Concept of lazy download will not work. Also there will be an attempt to make an unnecessary network connection, even though resources such as plugin.jar, javaws.jar etc are not hosted. This will increase initial applet/javaws startup time.

Use Image.width & Image.height: If we need to show a thumbnail of large image, its better to specify its width and height Image object itself rather than resizing the ImageView using fitWidth and fitHeight attribute. This will reduce the memory used to hold the image.

Provide Startup Feedback: Many a times people get bored due to lack of proper feedback during startup. This creates a notion of increased startup time. Except for small use-cases such as advertisements, RIA's do have some startup time. It will be nice to provide a Custom Splash Screen and even better a Progress Listener UI to give useful feedback.

Tips for Mobile: : Joshua Marinacci has listed some useful tips for mobile.

I'm sure there are more... 'll keep updating this list...

<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="/rakeshmenonp/resource/JavaFXPerfOpt/zoneit.js"></script>

Monday Nov 09, 2009

JavaFX - FPS Meter

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..

<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="/rakeshmenonp/resource/JavaFXFPSMeter/zoneit.js"></script>


The views expressed on this blog are my own and do not necessarily reflect that of my organization


« August 2016