« implemented code is nine-tenths of the law | Main | »
Friday
Nov112005

speeding up laszlo apps by replacing constraints with $once

Constraints are incredibly tasty for rapid prototyping, but they can lead to performance problems. Each constraint, of the form
<view name="nugget" width="${thingy.width}" ... / >
becomes, at runtime, something like this:
<method event="onwidth" reference="thingy" args="w" >
nugget.setWidth(w);
</method>

Every time thingy's width is changed, nugget's width is changed; that's the point of the constraints. If you don't care about maintaining that relationship, or if you know thingy.width is never going to change, then you're bloating the runtime with event handlers you don't need.

The $once "constraint" avoids the extra event handlers:
<view name="nugget" width="$once{thingy.width}" ... />

My understanding is that this constraint is just evaluated once, when the view's attributes are first set. This will only work for static layouts, of course, and only if instantiation order works right. In this case, thingy must be constructed, and its width attribute must be set, and "thingy" must be in scope, in order for the $once form to work.

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.

My response is on my own website »
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>