When you create a custom item renderer for a
List control you need to be very careful how many layout constraints you introduce in each component. What might seem harmless in a single item can quickly become a performance bottleneck when that item is recreated several hundred times in a list.
A few general rules of thumb:
Use exact measurements
This one is obvious. By specifying an exact location (x, y) and size (width, height) you reduce the number of constraints your application has to keep track of. While the effect may be minimal, it can really make a difference when manipulating large data sets.
Don’t abuse the
I learned this the hard way. Setting the
maxWidth property on as few as two components in an item renderer can ground your application to a halt, even with as few as a dozen items in your
Don’t resize components using percentage widths
This applies to complex item renderers that have one or more components that set the
maxWidth property, but in general its a good idea to resize your components absolutely. Even if you can only shave a few milliseconds off the rendering time it can make your application feel that much more responsive.
Avoid nesting containers
In general you should use as few containers as possible in your application, and item renderers are no exception. Nested containers create layer upon layer of constraints and can unnecessarily slow down your application. If you can, use a single layout container, and if at all possible, use a
Canvas container with absolute positioning. Even
VBox containers are heavier than
Move effects instead of changing (x, y, w, h) directly
Although it may seem counter-intuitive, using effects can actually improve the performance of your application. Processing large amounts of information when you move or resize components can result in your application being unresponsive. But if you use effects, you can take advantage of the
suspendBackgroundProcessing property to block all background processing while your components are being moved or resized. Even if you set the effect duration to 0ms you will still see an improvement in performance!
To summarize, when creating custom item renderers and
List controls, be aware of the effect your design decisions will have, especially on larger data sets. What may seem to be insignificant data-bindings can quickly add up to huge performance problems!