Best Practices for JavaFX Mobile Applications (Part 3)

WARNING: The tips I am giving here are true for the current version of JavaFX Mobile, which is part of the JavaFX 1.1 SDK. In future versions the behavior will change, the current bad performance of the mentioned artifacts will be optimized away or at least significantly improved. Everything I am writing about here is a snap-shot, nothing should be understood as final!


Item 3: Use simple shapes instead of images

Item 4: Use small images instead of complex shapes

These two items seem to contradict each other. Unfortunately there is no easy answer available here:  sometimes using shapes is better, sometimes using an image is better. To help making the right decision, here are some points one should consider:

  • Complexity Single basic shapes like rectangles or circles are almost always faster than images. But the higher the number of shapes, which are assembled to get the desired artifact, or the more complex a user-defined path is, the more expensive operations on these shapes are. And the advantage shrinks. Important note: A javafx.text.Text object is a very complex shape.
  • Size The performance of most operations on images behaves quadratic, which means the operations become 4 times as slow if width and height are doubled, 9 times as slow if they are tripled etc. Therefore the bigger an element is, the better is using shapes.
  • Transformations Rotating or scaling does not only look better when using shapes, but it is usually also faster than transforming images. Especially if rotation and scaling are animated, shapes will perform better.
  • Startup time Loading an image and setting up an ImageView is usually slower then setting up shapes.
  • Footprint Static and dynamic footprint is almost always higher when using images.

Important: The variable cache of javafx.scene.Node is currently NOT used in the runtime. Setting it makes no difference!

Links to previous parts:

Item 1: Avoid unnecessary bindings
Item 2: Keep the scenegraph as small as possible

Comments:

How do complex shapes compare with images when Node.cache is flipped on?

Posted by Bruno Garcia on February 24, 2009 at 05:20 PM CET #

Darn! I knew I forgot something really important in this post: the cache-variable. The cache-variable is currently NOT used in the JavaFX Mobile runtime!

Posted by Michael Heinrichs on February 25, 2009 at 12:30 AM CET #

Thanks a lot, Bruno! I updated the post.

Posted by Michael Heinrichs on February 25, 2009 at 12:36 AM CET #

Great series of articles, Michael. I'll be referring to these when I get into FX mobile. Also, the lack of caching on mobile should certainly be documented :)

Posted by Bruno Garcia on February 25, 2009 at 12:52 AM CET #

what's performance differences bind and/or bound function with on replace {call function or var foo = call function}

Posted by Tamer KARAKAN on February 26, 2009 at 06:30 AM CET #

Tamer,
it depends, I would say. A simple example I benchmarked became 4 times faster when the binding was removed. If you have a specific function in mind, you can measure the difference yourself. Simply change the bound value say a million times and measure how long it takes with bindings compared to using a trigger.

The runtime code for bound functions is pretty complex, I assume they are even slower.

Posted by Michael Heinrichs on February 26, 2009 at 07:21 AM CET #

I was always confused regarding complex shapes and images. Thanks for the vital information. It would help me in developing an application which I plan to showcase in Forum Nokia Developer Conference.

Posted by Subhodh on November 09, 2009 at 04:03 AM CET #

Post a Comment:
Comments are closed for this entry.
About

Michael Heinrichs

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