9 Replies Latest reply on Oct 13, 2010 4:36 AM by Harbs.

    CS3 script runs slow with CS4 and CS5

    lukaseb

      I have written a table transformation script for InDesign CS3, which formats an imported Excel table.

       

      With InDesign CS3 the script runs well. Now I tried the same script with InDesign CS4 and CS5 and it runs very slow. It's about 10 times slower than with CS3.

       

      I tried to turn off redrawing, but this didn't help. It even got slower again!

       

       

      Does someone has made similar experiences? Could you solve the performance issue?

       

      Do scripts in CS4/CS5 generally run slower than in CS3?

       

      Does CS4 differ so much to CS3 that the script runs 10 times slower?

       

      What can I do to improve the execution performance?

       

      Thanks for any tips / advices etc.

        • 1. Re: CS3 script runs slow with CS4 and CS5
          Fred Goldman Level 3

          Yes, I have seen the same thing and it specifically has to do with changeText() and ChangeGrep() in CS4. In CS5 findGrep() and fndText() are also 10x slower than CS3.

           

          The only solution I found was if the test is overset the find/changes go much much faster. Even a little faster than CS3. So if you can overset the text then do the find/changes and then reshow it, it will really speed up the script.

           

          At the end of this thread you will see some statistics:

           

          http://forums.adobe.com/thread/715817

          • 2. Re: CS3 script runs slow with CS4 and CS5
            lukaseb Level 1

            Hi Fred

             

            Thank you for your hint.

             

            My script does NOT use any changeText() or chageGrep() functions.

             

            But there are lots of iterations used in the script. Do you know if row/cell iterations became slower in CS4/CS5 compared to CS3?

            • 3. Re: CS3 script runs slow with CS4 and CS5
              Fred Goldman Level 3

              I don't know, but the ExtendScript Toolkit comes with a profiler that times how long the script takes. Go to Profile and set it to show timing and then set it to Lines and see which lines are taking longer in CS4 vs. CS3. Please let us know the results.

              • 4. Re: CS3 script runs slow with CS4 and CS5
                lukaseb Level 1

                I now have made some tests with profile / timing. Here are the results.

                • you find the code snipped below. It iterates first over all rows and then over all cells inside of the row. In the cell iteration, the function hasGapInLineBelow(...) does more iterations.
                • The example is with a table of 42 rows and 9 cells.
                • I have compared CS3 and CS5
                • there are 3 test cases:
                  • for 1/1 means: first for-loop is in iteration 1 and second for loop is in iteration 1 (statements for first row and first cell done)
                  • for 1/9 means: first for-loop is in iteration 1 and second for loop is in iteration 9 (statements for first row and all 9 cells of the row done)
                  • for 2/9 means: first for-loop is in iteration 2 and second for loop is in iteration 2 (statements for second row and all 9 cells of the row done)

                 

                Code Snippet.jpg

                 

                • it's strange that normal variable assignments take lot of time (like the statement startPos = indexLeftNeightbourOfCurrentCell;) -> I don't understand why this can be so time consuming!?!
                • it's also strange why in "for 1/9" and "for 2/9" variable assignments take much longer than in "for 1/1"...
                • could I use another data type than array for the variable isMergedRow? Which one?
                • do you know any performance optimizations?

                 

                • in which time unit ExtendScript Toolkit shows the measured periods?
                • how are the times calculated in loops? Are these the times sumed up over all iterations or is it just the time for a single statement?
                • 5. Re: CS3 script runs slow with CS4 and CS5
                  Fred Goldman Level 3

                  1,000,000 = 1 second I I think it's called microseconds).


                  The results are for all iterations.

                   

                  I don't understand how you got the timing in middle of the iterations. Did you set conditional breakpoints? The profiler continues timing while the script is paused, too. The best way to time is to run the full script in CS5 and CS3 and then see which lines took considerably longer inCS5.

                  • 6. Re: CS3 script runs slow with CS4 and CS5
                    lukaseb Level 1

                    ah, I thought when I run into a breakpoint, the timing would also be paused...

                     

                    I now have optimized some statements inside of loops. E.g. instead of calculate the table rows inside every iteration, I placed it outside of the loop:

                     

                    before optimization:

                     

                    for(...){

                         var item = TABLE.rows.item(i);

                    }


                    after optimization:

                     

                    var tableRows = TABLE.rows;

                    for(...){

                         var item = tableRows.item(i);

                    }

                     

                    I found several similar statements like the one written above. This made my script about 25% faster in CS5. But it's still slower than in CS3...

                    • 7. Re: CS3 script runs slow with CS4 and CS5
                      Harbs. Level 6

                      Getting accurate profiles from the ESTK is not really practical.

                       

                      The times when run from the ESTK is not necessarily indicative of the times you will get when running the script from the scripts panel.

                       

                      If you really want accurate results, you are going to have to log the times yourself. (hint: for best results, use $.hiresTimer...)

                       

                      Harbs

                      • 8. Re: CS3 script runs slow with CS4 and CS5
                        lukaseb Level 1

                        Thank you for your hint.

                         

                        I just need to compare, real time informations are not so important. I think for this purpose the time informations from ESTK will suffice, won't they?

                        • 9. Re: CS3 script runs slow with CS4 and CS5
                          Harbs. Level 6

                          Maybe yes, maybe no...

                           

                          The comparisons will not necessarily be accurate.

                           

                          Harbs