[flexcoders] Re: Why is this renderer so slow?

2008-05-24 Thread dbronk




Fill up the yourCollection with a bunch of objects or xml with a field
named yourBooleanField.  Run it and they will initially display fine.
 Select some, unselect others.  Scroll them off the page the scroll
them back into view and their state will not be kept.

I posted a question about that and Tracy set me straight with an
example (I tweeked it a bit as I needed and is the renderer in my post
here).  He gave me a couple links about why I had to write a checkbox
renderer for it to remember state.

I'll look into the option given by the other response to this tread.

Thanks,
Dale





--- In flexcoders@yahoogroups.com, leds usop <[EMAIL PROTECTED]> wrote:
>
> im just wondering why you think an ordinary check box wont retain
it's selected state when scrolling? can you provide an example code
that does that? maybe it will be more beneficial to approach the
problem using that approach. Just a thought. 
> 
> 
> --- On Sun, 5/25/08, dbronk [EMAIL PROTECTED] wrote:
> From: dbronk [EMAIL PROTECTED]
> Subject: [flexcoders] Why is this renderer so slow?
> To: flexcoders@yahoogroups.com
> Date: Sunday, May 25, 2008, 12:59 AM
> 
> I have created a checkbox renderer.  My datagrid has 5 out of 8
>  columns that use it.  The datagrid has only about 80 rows it it.  When
>  using this renderer the performance of the datagrid is horrible. 
>  Scrolling is extremely slow, click a checkbox is extremely slow.  If I
>  swap out and use a normal mx:CheckBox for the renderer the performance
>  is just fine, but of course that doesn't work as it will not retain
>  the state of the checkbox when scrolling.  Here is my code for the
>  renderer.  I notice that many of these are re-executed whenever
>  anything happens to the datagrid.  That includes just mousing over.
> 
>  Thanks.
> 
>  Dale
> 
>  package renderer
>  {
>   import flash.events. MouseEvent;
> 
>   import mx.controls. CheckBox;
> 
>   import spectrumk12. minerva.util. BaseEvent;
>   import spectrumk12. minerva.util. Utils;
> 
>   [Event(name= "selectionSet" , type="util.BaseEven t")]
>   public class RendererCheckBoxXML extends CheckBox
>   {
>   private var _xmlItem : XML;//holds the current item xml node
>   private var count:int=0;
>   private var debug:String= "";
> 
>   /** The attribute in the xml to use to store the selected state 
> of
>  this checkbox. */
>   [Inspectable( default=" rendererSelected ")]
>   public var selectedAttribute : String = "rendererSelected" ;
> 
>   /** The default selection state (true/false) to give if the
>  selectedAttribute is not there or null */
>   [Inspectable( default=" false", enumeration= "true,false" )]
>   public var defaultSelectedStat e : Boolean = false;
> 
>   public function RendererCheckBoxXML ()
>   {
>   super();
>   trace("RendererChec kBoxXML:Construc tor");
>   this.addEventListen er(MouseEvent. CLICK, onClick, 
> false, 0, true);
>   }
> 
>   // Sets the state of the checkbox based on the selectedAttribute
>  attribute.
>   override public function set data(oItem:Object) : void
>   {
>   _xmlItem = XML(oItem);
>   trace("RendererChec kBoxXML:set data: " + [EMAIL 
> PROTECTED]) ;
>   var bSelected : Boolean = false;
>   var attrSelected : String = [EMAIL PROTECTED] 
> Attribute] ;
>   this.selected = ( Utils.nullOrBlank( attrSelected) ?
>  defaultSelectedStat e : (attrSelected == "true") ); 
>   }
> 
>   override public function get data() : Object
>   {
>   trace("RendererChec kBoxXML:get data: " + (_xmlItem != 
> null ?
>  [EMAIL PROTECTED] : "null"));
>   return _xmlItem;
>   }
> 
>   /**
>* This overridden function is where the logic is for updating
the xml.
>*/
>   override public function set selected(selectedFl ag:Boolean) : 
> void
>   {
>   trace("RendererChec kBoxXML:set selected: " + [EMAIL 
> PROTECTED]) ;
>   super.selected = selectedFlag;
> 
>   // Only update the xml if it needs to be updated.  Each 
> time the xml
>   // is updated it will fire any bindings to it so we 
> want to keep
these
>   // to a minimum.
>   if ( [EMAIL PROTECTED] Attribute] != selectedFlag )
>   {
>   // The selected flag is different than the 
> selectedAttribute
>  attribute.
>   // Now we make one last check to see if the 
> selectedFlag is
false and
>   // there is no attr

[flexcoders] Re: Why is this renderer so slow?

2008-05-25 Thread dbronk
Thanks, I'll take a look at that.  I dispatched the event because I
needed to determine if the checkbox needed to be hidden (different
post).  But, adding the dispatch really did nothing for the
performance.  It was just as slow before I added the dispatchEvent.

Thanks again for your suggestion.
Dale


--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> Updating the dataprovider is costly. Make sure it only happens when
> required (that is isn't happening during scrolling), and maybe avoid
> dispatching an event to do it.  I'm not sure who's listening and what
> they will do in response.  If you change the dataprovider, the DataGrid
> will do a lot of work.
> 
>  
> 
> XML is much slower than objects, so it may pay to convert to object.
> 
>  
> 
> Button already has logic for handling a selectedField in a dataprovider
> item.  Since CheckBox inherits from button, you might just be able to
> use selectedField, or modify and piggy-back on its timing.
> 
>  
> 
> 
> 
> From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
> Behalf Of dbronk
> Sent: Saturday, May 24, 2008 10:00 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Why is this renderer so slow?
> 
>  
> 
> I have created a checkbox renderer. My datagrid has 5 out of 8
> columns that use it. The datagrid has only about 80 rows it it. When
> using this renderer the performance of the datagrid is horrible. 
> Scrolling is extremely slow, click a checkbox is extremely slow. If I
> swap out and use a normal mx:CheckBox for the renderer the performance
> is just fine, but of course that doesn't work as it will not retain
> the state of the checkbox when scrolling. Here is my code for the
> renderer. I notice that many of these are re-executed whenever
> anything happens to the datagrid. That includes just mousing over.
> 
> Thanks.
> 
> Dale
> 
> package renderer
> {
> import flash.events.MouseEvent;
> 
> import mx.controls.CheckBox;
> 
> import spectrumk12.minerva.util.BaseEvent;
> import spectrumk12.minerva.util.Utils;
> 
> [Event(name="selectionSet", type="util.BaseEvent")]
> public class RendererCheckBoxXML extends CheckBox
> {
> private var _xmlItem : XML; //holds the current item xml node
> private var count:int=0;
> private var debug:String="";
> 
> /** The attribute in the xml to use to store the selected state of
> this checkbox. */
> [Inspectable(default="rendererSelected")]
> public var selectedAttribute : String = "rendererSelected";
> 
> /** The default selection state (true/false) to give if the
> selectedAttribute is not there or null */
> [Inspectable(default="false", enumeration="true,false")]
> public var defaultSelectedState : Boolean = false;
> 
> public function RendererCheckBoxXML()
> {
> super();
> trace("RendererCheckBoxXML:Constructor");
> this.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
> }
> 
> // Sets the state of the checkbox based on the selectedAttribute
> attribute.
> override public function set data(oItem:Object) : void
> {
> _xmlItem = XML(oItem);
> trace("RendererCheckBoxXML:set data: " + [EMAIL PROTECTED]);
> var bSelected : Boolean = false;
> var attrSelected : String = [EMAIL PROTECTED];
> this.selected = ( Utils.nullOrBlank(attrSelected) ?
> defaultSelectedState : (attrSelected == "true") ); 
> }
> 
> override public function get data() : Object
> {
> trace("RendererCheckBoxXML:get data: " + (_xmlItem != null ?
> [EMAIL PROTECTED] : "null"));
> return _xmlItem;
> }
> 
> /**
> * This overridden function is where the logic is for updating the xml.
> */
> override public function set selected(selectedFlag:Boolean) : void
> {
> trace("RendererCheckBoxXML:set selected: " + [EMAIL PROTECTED]);
> super.selected = selectedFlag;
> 
> // Only update the xml if it needs to be updated. Each time the xml
> // is updated it will fire any bindings to it so we want to keep these
> // to a minimum.
> if ( [EMAIL PROTECTED] != selectedFlag )
> {
> // The selected flag is different than the selectedAttribute
> attribute.
> // Now we make one last check to see if the selectedFlag is false and
> // there is no attribute selectedAttribute. If this is the case, then
> // we do NOT update because having no attribute selectedAttribute will
> // default to a false. Again, we do this so that we update the xml as
> // infrequently as possible.
> if ( selectedFlag || [EMAIL PROTECTED]() > 0 )
> {
> [EMAIL PROTECTED] = String(this.selected); //set the
> checkbox state into the dataProvider
> }
> }
> dispatchEvent(new BaseEvent("selectionSet", selectedFlag));
> }
> 
> // Called by click of the checkbox
> private function onClick(mouseEvent:MouseEvent) : void
> {
> trace("RendererCheckBoxXML:onClick: " + [EMAIL PROTECTED]);
> // Simply need to trigger the set selected function as that is
> where the logic for updating the xml is.
> this.selected = this.selected; 
> }
> 
> }
> }
>




[flexcoders] Re: Why is this renderer so slow?

2008-05-27 Thread Tracy Spratt
Also, it looks like you are doing some work in the set data() 
method.  This method gets called more often than you might expect.  
Consider, in the set data(), storing the data in a local var then 
calling invalidateProperties(), then actually do the work in 
commitProperties().  I think maybe I learned that after I created 
that example.

Tracy


--- In flexcoders@yahoogroups.com, "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> Updating the dataprovider is costly. Make sure it only happens when
> required (that is isn't happening during scrolling), and maybe avoid
> dispatching an event to do it.  I'm not sure who's listening and 
what
> they will do in response.  If you change the dataprovider, the 
DataGrid
> will do a lot of work.
> 
>  
> 
> XML is much slower than objects, so it may pay to convert to object.
> 
>  
> 
> Button already has logic for handling a selectedField in a 
dataprovider
> item.  Since CheckBox inherits from button, you might just be able 
to
> use selectedField, or modify and piggy-back on its timing.
> 
>  
> 
> 
> 
> From: flexcoders@yahoogroups.com 
[mailto:[EMAIL PROTECTED] On
> Behalf Of dbronk
> Sent: Saturday, May 24, 2008 10:00 AM
> To: flexcoders@yahoogroups.com
> Subject: [flexcoders] Why is this renderer so slow?
> 
>  
> 
> I have created a checkbox renderer. My datagrid has 5 out of 8
> columns that use it. The datagrid has only about 80 rows it it. When
> using this renderer the performance of the datagrid is horrible. 
> Scrolling is extremely slow, click a checkbox is extremely slow. If 
I
> swap out and use a normal mx:CheckBox for the renderer the 
performance
> is just fine, but of course that doesn't work as it will not retain
> the state of the checkbox when scrolling. Here is my code for the
> renderer. I notice that many of these are re-executed whenever
> anything happens to the datagrid. That includes just mousing over.
> 
> Thanks.
> 
> Dale
> 
> package renderer
> {
> import flash.events.MouseEvent;
> 
> import mx.controls.CheckBox;
> 
> import spectrumk12.minerva.util.BaseEvent;
> import spectrumk12.minerva.util.Utils;
> 
> [Event(name="selectionSet", type="util.BaseEvent")]
> public class RendererCheckBoxXML extends CheckBox
> {
> private var _xmlItem : XML; //holds the current item xml node
> private var count:int=0;
> private var debug:String="";
> 
> /** The attribute in the xml to use to store the selected state of
> this checkbox. */
> [Inspectable(default="rendererSelected")]
> public var selectedAttribute : String = "rendererSelected";
> 
> /** The default selection state (true/false) to give if the
> selectedAttribute is not there or null */
> [Inspectable(default="false", enumeration="true,false")]
> public var defaultSelectedState : Boolean = false;
> 
> public function RendererCheckBoxXML()
> {
> super();
> trace("RendererCheckBoxXML:Constructor");
> this.addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
> }
> 
> // Sets the state of the checkbox based on the selectedAttribute
> attribute.
> override public function set data(oItem:Object) : void
> {
> _xmlItem = XML(oItem);
> trace("RendererCheckBoxXML:set data: " + [EMAIL PROTECTED]);
> var bSelected : Boolean = false;
> var attrSelected : String = [EMAIL PROTECTED];
> this.selected = ( Utils.nullOrBlank(attrSelected) ?
> defaultSelectedState : (attrSelected == "true") ); 
> }
> 
> override public function get data() : Object
> {
> trace("RendererCheckBoxXML:get data: " + (_xmlItem != null ?
> [EMAIL PROTECTED] : "null"));
> return _xmlItem;
> }
> 
> /**
> * This overridden function is where the logic is for updating the 
xml.
> */
> override public function set selected(selectedFlag:Boolean) : void
> {
> trace("RendererCheckBoxXML:set selected: " + [EMAIL PROTECTED]);
> super.selected = selectedFlag;
> 
> // Only update the xml if it needs to be updated. Each time the xml
> // is updated it will fire any bindings to it so we want to keep 
these
> // to a minimum.
> if ( [EMAIL PROTECTED] != selectedFlag )
> {
> // The selected flag is different than the selectedAttribute
> attribute.
> // Now we make one last check to see if the selectedFlag is false 
and
> // there is no attribute selectedAttribute. If this is the case, 
then
> // we do NOT update because having no attribute selectedAttribute 
will
> // default to a false. Again, we do this so that we update the xml 
as
> // infrequently as possible.
> if ( selectedFlag || [EMAIL PROTECTED]() > 0 )
> {
> [EMAIL PROTECTED] = String(this.selected); //set the
> checkbox state into the dataProvider
> }
> }
> dispatchEvent(new BaseEvent("selectionSet", selectedFlag));
> }
> 
> // Called by click of the checkbox
> private function onClick(mouseEvent:MouseEvent) : void
> {
> trace("RendererCheckBoxXML:onClick: " + [EMAIL PROTECTED]);
> // Simply need to trigger the set selected function as that is
> where the logic for updating the xml is.
> this.selected = this.selected; 
> }
> 
> }
> }
>