Skip navigation
Currently Being Moderated

Help with performance

Mar 26, 2013 5:39 AM

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.

 
Replies
  • Currently Being Moderated
    Mar 26, 2013 7:58 AM   in reply to jfb00

    What is acSummary?

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 26, 2013 10:31 AM   in reply to jfb00

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 27, 2013 4:24 AM   in reply to jfb00

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

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 27, 2013 7:45 AM   in reply to jfb00

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 27, 2013 10:10 AM   in reply to jfb00

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Mar 27, 2013 10:12 AM   in reply to DeanLoganBH

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points