Lazy deserialization improves WebService performance in Flash MX 2004

In response to a support request for our charting components I was looking into how a v1 component utilizes a v2 data source, such as the results from a WebServiceConnector. In stepping through the code, I noticed something surprising: the XML returned from the web service is deserialized on an as-needed basis instead of all at once. In the XML world this is called “lazy deserialization” and it’s a big feature I’ve never heard anyone mention as related to Flash MX 2004.

Curious? Here’s how it works…

To demonstrate I set up a simple movie that has three components: a DataGrid, a Button, and a WebServiceConnector. The WebServiceConnector is set to point to a stock news service with results bound to the DataGrid. I set up a behavior on the Button to trigger the WebServiceConnector. Finally, I added a line of code to the WebServiceConnector’s result event and the DataGrid’s scroll event with breakpoints to examine the data as it’s used.

Slide One -- initial results

This image represents the WebServiceConnector results within the result event. As you can see the results, which is an array, shows only one element in it as position [0]. However, there is some extra data there and one item is an xmlNodes array which more than 16 items (actually, there are 20 total). Despite the fact that the results only has one element in the array, the DataGrid still displays all data. Pretty kewl, let’s investigate further…

Slide One -- initial results

So here we see the DataGrid displayed 11 rows of data. The breakpoint was on the scroll event and I clicked the down arrow, so we’re scrolling to show the 12th record.

The debug window is showing the data provider attached to the DataGrid. As we can see it’s an array with 13 elements, [0] through [12] but the length is 20. So the data provider knows there is 20 items but only deserialized data for 13 of them (11 rows displayed, plus 12th row being displayed, plus one–not sure why plus one).

Very kewl. Now lets scroll again and see what happens…

Slide One -- initial results

This looks a lot like the previous shot. We scrolled down one row and the now the data provider has deserialized one more row. Let’s scroll to the end.

Slide One -- initial results

This is it, we’ve scrolled to the end of the list. The array now has all 20 items, numbered [0] through [19].

This is really a nice feature that all components can take advantage of just by using the prescribed data provider methods as opposed to direclty accessing data provider elements.

The real remaining mistery is why this isn’t hyped up–it’s a nice implementation. The only reference I could find related to Flash is a comment from Kevin Hoyt in one of Christian Cantrell’s weblog posts. However, the comment is forward-looking and the feature exists today. Interesting.

2 thoughts on “Lazy deserialization improves WebService performance in Flash MX 2004

  1. It *definitely* helps time-to-interactivity. But as always, a double-edged sword. Adds a little it of work to dataGrid scrolling, which is already a *very* intensive process.

  2. fyi, the web service API within Central works the same. There is a property or method to disable this (at least in Central), although I don’t recall it off the top of my head.

    I will post it here when I find it.

    mike chambers

    mesh@macromedia.com

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>