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 Feb 08, 2010

Java Download Service Listener


One of the previous post [Applet Startup Time] provided a way to measure start-up time of JavaFX Applets. Many responded with requested information (Thanks a lot!). One of the main concern raised was high start-up time for "Without JavaFX Runtime". This is high because it includes time taken to download and install JavaFX Runtime.

Unfortunately there was no way to notify the user about exact progress of this. Hence user will not be able to differentiate between download and install of "JavaFX Runtime" and "JavaFX Application".

Recent JavaFX Update 1.2.3 reduced the download size and start-up time. You can notice this change by trying out the start-up time measurement applet again.. But still it doesn't provide a way to exactly notify the start-up progress. We can only specify a custom splash-screen as specified here.

And then we have Java Update 1.6.0_18 - [Download Now] - Not sure how many of you noticed this feature - Download Service Listener It allows you to provide a Custom Progress UI using AWT/Swing/Java2D APIs. It has callback methods which will provide information related to download and validation of resources. Please refer to Download Service Listener Example for more information. Refer to ProgressListener.java and ProgressView.java for implementation used in this sample.

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="http://javafxdemos.googlecode.com/hg/resource/ProgressListener/ProgressListenerFX.js"></script>


To launch click on above image or

Now we can implement custom progress listener with actual values. We can use the same approach for JavaFX applications as well. There is minor issue in using this feature with JavaFX Applet deployed using dtfx.js. This script is not updated to utilize this feature. So for now we need to explicitly hide the default splash screen by invoking JavaScript method hideOverlay as shown in ProgressListenerFX.html

Reference:

Hmm.. thatz a long post with lots of information.. But I think its very useful.. As usual, please try it out and let me know feedback..


<script type="text/javascript">var dzone_style = '2';</script> <script language="javascript" src="http://javafxdemos.googlecode.com/hg/resource/ProgressListener/zoneit.js"></script>

Monday Aug 31, 2009

JavaFX - Applet Startup Time


We keep getting various numbers related to JavaFX applet startup time. Yes this is very important and we need a consistent way to measure this and compare. Here is an attempt..

Update:

When the page is loaded, the system time is noted using JavaScript. Time is again noted once Applet is loaded. Difference between time obtained in Applet and JavaScript is computed to be startup time. I think this will be fair and consistent way to measure startup time. This requires JavaSE 6 Update 10 and above. It will be good to try out a few times and get the average number..

<script src="http://dl.javafx.com/1.2/dtfx.js"></script> <script src="/rakeshmenonp/resource/Startup/Startup.js"></script>

User Without JavaFX
Runtime
Load
Applet
Re-load
Applet
Rakesh Menon453.000.70
Pär Dahlberg-7.270.66
Julien Buret-1.710.32
cozmint-7.831.55
Philippe Lhoste-3.420.98
Ernie Kent-4.730.66
Carl Dea - FF-5.740.63
Carl Dea - IE-3.340.74
Simon Brocklehurst-3.120.79
Tom Eugelink-2.680.64
Guido-2.560.62
GC - WinXP-64bit FF-64bitError
Carl Antaki-4.060.67
Nick Apperley-3.270.83
Andy Xie478.321.05
Wojciech Halicki-Piszko-4.450.8
Endre Stølsvik723.80-
Chui Tey - Chrome 2.0.172.43-6.952.86
Chui Tey - MSIE 8.0.6001.18702IS-3.220.70
Chui Tey - FF 3.0.10-4.130.70
JosK (Intel Core 2CPU 4300@1.8GHZ (1,93GB) 512RAM) - Chrome 2.0.172.43-4.264.08
JosK (Intel Core 2CPU 4300@1.8GHZ (1,93GB) 512RAM) - Chrome 3.0.195.21-3.981.05
JosK (Intel Core 2CPU 4300@1.8GHZ (1,93GB) 512RAM) - IE 8.0.6001.18702-8.331.06
Jonathan (Quad Core Q9300 @ 2.5GHZ, 4GB ram JRE 1.6u15)15.50-0.52
Thierry (2 year olds windows dual core basic PC)17.503.10-
Robrecht (Windows xp SP2 Intel Core 2 cpu T5600 @ 1,83GHz, 2GB Ram jre: 1.6.0_15)4.832.800.62
Venkateswara Rao Desu (Fedora 9 JDK 1.6_10)Applet not initialized
André Costa-1.910.42
Joeri Sykora (jdk 1.6.0_16 in Firefox 3.5.3)-1.020.65
Thustle (1.6.0_16 on Chrome v3 on Vista 32bit Intel Core2 Quad Q6600 2.4GHz 4GB)-9.300.74
Vance (Intel Core 2 Duo P8700 2.53GHz/1066Mhz RAM:4GB, DDR3, 1067 MHz, Ubuntu 9.10, FireFox 3.5.5, JRE: 1.6.0_15, Connection: comcast high-speed cable)7.62.30.3
Venkateswara Rao Desu (Fedora 11 Firefox 3.5.5 Sun Java Plugin)17.00-0.70
Venkateswara Rao Desu (Windows XP Java 1.6.0_18)9.3-0.38
Jor (WinXP, FF 3.5.7, Java 1.6.0_17)36-0.21

Legend:

  • Without JavaFX Runtime - After clearing Java Web Start cache - [ javaws -uninstall ] May have to wait for sometime as clearing process may be running in background. This is the time taken to download JavaFX runtime and load the applet.
  • Load Applet - Launch browser and load applet (JavaFX runtime already installed)
  • Re-Load Applet - Re-load the page after loading applet
  • Duration - specified in seconds


Please launch the applet and let me know the start-up time with system configuration and connection speed.. Thanks in advance..

About


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

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today