My Top Laszlo Performance Tips

A customer recently asked if I had a list of Laszlo coding, performance, & style tips. I didn’t, so I thought I’d start by creating a list of performance tips. Anyway, here’s my list (in no particular order)

  • When using constraints, use $once{} as often as possible – Constraints are a great time saver, but they come at a cost. Normal constraints have to have their events registered when the application starts up, so if you have a lot of constraints, this can slow things down. If you don’t need the constraint to update after application startup, use $once{} for an incremental performance improvement.
  • Use short variable names – I believe this was more of an issue with older versions of the Flash player, so I’m not sure how relevant this is, but it is my understanding that because of the nature of Javascript, long variable names actually have a negative performance impact. If you look at any of the Laszlo run time source code, you’ll see most of the variable names are VERY short, to the point that it makes the code hard to read.
  • Use pooling and lazy replication for replicated views as often as possible – Take advantage of the hard work Adam put into making these features work. Pooling reuses previously replicated views, improving the rendering time when a datapath is updated. Lazy replication only replicates the visible views, hence saving lots of time in the event you have a scrolling list of say hundreds of replicated nodes. You’ll likely need to tweak your code to get these two features to work, but the performance gain you get is totally worth it.
  • Minimize the number of views used – Views are expensive to instantiate, so do what you can to minimize the number of views generated. Focus on classes that are constructed often via replication or other means. For example, in our diagram editor every shape contains ‘connection points’ which are represented by little ‘+’ symbols. Originally, we created the ‘+’ with two views (one horizontal, and one vertical). By using a single asset for the ‘+’ symbol, we cut the number of constructed views down substantially for each shape, yielding faster diagram load times.
  • Load images at run-time – If you don’t need to display an image right away, consider loading the image at run time to reduce the initial application download size.
  • Delay instantiation – Delay instantiation on any views that wont be shown right away to improve start-up performance. For example pop up windows, drop down menus, etc.
  • Use local variables when possible – I think this is another issue that is less important with the newer Flash players, but probably worth looking into. Apparently accessing global variables can be slow, so you’re better off creating a local reference to the global variable if you are going to access it a bunch in a loop.
  • Using Debug.write() can slow things down even when the debugger is off – If you want to be fancy, you could do something like if( $debug) Debug.write(‘some message’); The compiler is smart enough to remove the $debug statements kind of like a pre-processor.

Did I miss anything? Feel free to clue me in, and I’ll add to the list here.

8 thoughts on “My Top Laszlo Performance Tips

  1. Nice post, Chris. We’re programming a lot in LZX and this information is really valuable. Thanks for sharing this information with us. At the next Berlin Laszlo User Group meeting I want to discuss these tips with the other members.

    Best, Raju

  2. Pingback: » Blog Archive » OpenLaszlo Tips and Tricks

  3. We used the data replication but have some problems with duplicates . ie say suppose i am having list of 10 items, each have an unique id associated with it, we are using the unique id for further features. but with lazy replication, the unique id’s are not the same as dataset, its get repeated in the laszlo front, Can you help us , Thanks in Advance

  4. ME,

    I’m pretty sure setting an id on a replicated view isn’t supported. There is probably a better solution to the problem you are solving. Why do you need to set an id on the replicated view? I’d recommend posting a simplified code example of the issue you are having to the OpenLaszlo mailing list to make it easier for folks to help you out.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s