9 Replies Latest reply on Mar 27, 2013 10:12 AM by Flex harUI

    Help with performance

    jfb00 Level 3

      Hi all,

      We are doing multiple calculations inline (actionScript) after getting data from oracle db. Each item is added to an arrayCollection after doing the calcualtion stored in an Object like:

                      tempObject = new Object();

                      tempObject.ID = 1;

                      tempObject.DESC = "Calculation 0ne";

                      tempObject.NAME = 'Name one';

                      for (i=1; i <= yearsLength; i++){ //Where yearsLength is an arrayCollection with 10 years

                          tempObject["YEAR_" + i] = acArrayDB[0].ITEM1 * acArrayDB[0].ITEM4 / acSummary[34].TOTAL_ITEM;

                      }

                      acSummary.addItem(tempObject);

      We have more than 150 calculations in a page and it is taking a long time to load. Is this a good way to do it or it is a better way?

      Thanks.

        • 1. Re: Help with performance
          Zolotoj Level 3

          What is acSummary?

          • 2. Re: Help with performance
            jfb00 Level 3

            Thanks for you reply and help.

            Is an array collection, it contains results from the database. As you see new calculations are stored in the same array collection becuase at the end i display all in one report.

            Best,

            • 3. Re: Help with performance
              DeanLoganBH Level 3

              How are you displaying the data?

               

              You could use a ItemRenderer to do the calculation when the item is displayed.  Of course, if you display the entire ArrayCollection, you will probably run into the same performance issue.

              • 4. Re: Help with performance
                jfb00 Level 3

                Hi,

                I am using the advancedDatagrid to display all data from the array collection "acSummary."

                Any other ideas?

                Thanks!

                • 5. Re: Help with performance
                  DeanLoganBH Level 3

                  You could limit the rows in your DataGrid and use pagenation to show more data.

                  • 6. Re: Help with performance
                    jfb00 Level 3

                    We still need to do the calculations, I don't think the display here is an issue. The performance issue is with the calculations. I wonder if anyone else does calculations in different way. We use coldfuison in the back end, I will try to do the calculations in the cfc before I call into the form, maybe there the calculations are faster.

                    Thanks for trying.

                    • 7. Re: Help with performance
                      DeanLoganBH Level 3

                      As part of displaying the column with the ItemRenderer, do the calculation.

                       

                      Server side calculations would probably be faster.  Database calculations would be even faster.

                      • 8. Re: Help with performance
                        Sean@Tier1CRM

                        Maybe you can try casting the values in the acArrayDB before attempting to do the calculations. From what I recall reading about performance and arrays (not 100% sure if this applies to array collections but I assume yes because the underlying source is a weakly typed array), is that it does some ridiculous casting if you don't force the runtime to cast it as something specific.

                         

                        See here for the reference

                         

                        http://www.nbilyk.com/optimizing-actionscript-3

                         

                        Here's a snippet about what I'm referring to:

                         

                         

                        function calculateSum(arr:Array):Number {
                            var sum:Number = 0;
                            for (var i:Number = 0; i < arr.length; i++) {
                                sum += arr[i];
                            }
                            return sum;
                        }
                        

                         

                        "There are several things wrong with that code, 1. Arrays are mutable, so when you say i < my_arr.length as your maintenance condition, the length of the array needs to be re-calculated on every iteration.  Yuck! Instead, store a local variable with the length before the iteration (This is even more important when it comes to Strings).  2. The array element isn't being properly cast, so it's being treated like an Object and what's actually happening is this: sum += Number(Object(my_arr[i]).toString());   That's no good, jack."

                         

                        The benchmarks are significantly different (though the record size is pretty large), but might as well give it a shot.

                        • 9. Re: Help with performance
                          Flex harUI Adobe Employee

                          And you can try using pseudo-threading if you’re desperate.