Monday, March 17, 2014

Designing and developing Stock Ticker application in Flex (Part Two)

As we mentioned in Part One there are two aspects yet to be optimized:

  1. Removing the Bindable tag as it is an overhead and a performance killer and control it ourselves.
  2. Controlling the data grid redraw as every price change is redrawing the whole grid.

Now as we know when we change the price of a stock it leads to collection change event and it leads to full redraw of the grid. There is one idea  here where we can prevent the collection change event of update kind and will make the item renderer responsible for the update part. In this case the datagrid will not be redrawn every time and will be a performance booster.

Another option I can think of is invalidateCell() method in the spark datagrid. 
public function invalidateCell(rowIndex:int, columnIndex:int):void

This method is handy when the specified cell is visible. If the specified cell is visible, it is redisplayed. If variableRowHeight=true, then doing so may cause the height of the corresponding row to change.
If columnIndex is -1, then the entire row is invalidated. Similarly if rowIndex is -1, then the entire column is invalidated.
This method should be called when there is a change to any aspect of the data provider item at rowIndex that might have some impact on the way the specified cell is displayed. Calling this method is similar to calling the dataProvider.itemUpdated() method, which advises the Grid that all rows displaying the specified item should be redisplayed. Using this method can be relatively efficient, since it narrows the scope of the change to a single cell.

This optimizes the redraw of the datagrid as well. Now we need to optimize the code so as to remove Bindable meta data tag. Part 3.

No comments: