OpenLaszlo Performance Tip: offsets

I’m not sure if Laszlo Systems would approve of this, but I found something that improves the speed of rendering views that are changing their dimensions or positions rapidly. In our application, we need to resize and move many views all at the same time, repeatedly. During all this, we also need to adjust xoffset and yoffset since these views might be rotated. All this view morphing puts a heavy strain on the system, and performance noticeably suffers as a result. I was poking around in the OpenLaszlo source code, and discovered that when you set the xoffset or yoffset attributes using setAttribute(), setX() and setY() are invoked internally.

Our code looked something like this:

   while( aBunchOfTimes ) {
        //setX() and setY() invoked internally by LzView
        someView.setAttribute('xoffset', someView.width/2 );
        //setX() and setY() invoked internally by LzView
        someView.setAttribute('yoffset', someView.height/2 );
        someView.setX( anewx );
        someView.setY( anewy );

In the above case, setX() and setY() are being invoked a total of 6 times. It turns out that setX() and setY() and costly enough operations that this is worth optimizing. How do we speed things up? I went ahead and changed the above code to look something like this:

   while( aBunchOfTimes ) {
        someView.xoffset = someView.width/2;
        someView.yoffset = someView.height/2;
        someView.setX( anewx );
        someView.setY( anewy );

What’s going on here? setAttribute(‘xoffset’) and setAttribute(‘yoffset’) cause internal functions to be invoked which in turn invoke setX() and setY(). If you assign a value to xoffset and yoffset directly, as I’ve shown in this last example, the internal functions are not invoked. When I finally do invoke setX() and setY() on my own, the OpenLaszlo view system does whatever it needs to do with xoffset and yoffset to keep everything in order. It turns out this simple change made a very noticeable performance improvement in our application. (Clint said, “It’s smooth like butter!”)

Yay for open source!

It’s important to note that this optimization now depends on specific internal behavior of the OpenLaszlo view system. Obviously, this goes against the rules of code abstraction, and we run the risk that our application might break if the internal workings of the OpenLaszlo view system change significantly. In our first round of user testing, we found that performance was a significant factor in making happy users, so we think this risk is worth it.

One thought on “OpenLaszlo Performance Tip: offsets

  1. Pingback: Raju Bitter - OpenLaszlonaut » Blog Archive » Laszlo Performance Tips

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