Re: Strange Bottleneck
Re: Strange Bottleneck
- Subject: Re: Strange Bottleneck
- From: Steve Cunningham <email@hidden>
- Date: Sun, 8 Jun 2003 05:18:44 -0400
>
Steve Cunningham wrote on Thu, 5 Jun 2003 17:04:32 -0400:
>
>
>I have written a script to handle matrices or tables in AppleScript.
>
>
>Works great... except as the size of the matrix gets larger, the time to
>
>stuff the matrix increases in an anomalous, non-linear manner. To
>
>illustrate, I have included only the code to generate the matrix by rows
>
>below. The problem is that when adding rows, the columns take 10 times
>
>longer to generate for the later rows than for the earlier rows. The
>
>problem is the line:
>
>
>
>set item nn of columns to insert_listitem(item nn of columns, item nn of
>
>valueList, newRow)
>
>
>
>which I have highlighted in the listing.
>
>
>
>What I am having difficulty in understanding is why the time to build a
>
>given column should increase almost by an order of magnitude from the
>
>first to the last. Once the first row is built, the number of columns and
>
>the number of items in the valuelist are constant, so why should I be
>
>seeing such wide variation? In the example below, every iteration handles
>
>exactly 90 values for each row. I can't see any material difference
>
>between row 2 and row 40, yet the colums are updated for row 2 in 4 ms
>
>while it takes 34 ms to update row 40.
>
>
Nigel Garvey wrote:
>
>
This seems to be connected with the time it takes to access 'item nn of
>
columns'. The "Serge" method for speeding up list-item access makes a
>
great difference here (on my machine). Try changing the line you've
>
quoted above to:
>
>
set item nn of my columns to insert_listitem(item nn of my columns,
>
item nn of valueList, newRow)
>
>
"Me" in this case is the script object 'matrix'. By refering to its
>
property 'columns' as 'my columns', you're using a reference to the
>
property rather than the property itself, which is much faster (for
>
various arcane reasons) when accessing numbered items in the list.
>
>
I still get one or two timings that stand out as being much longer than
>
the others, but these seem to be more to do with random factors on my
>
machine than with the script itself.
Thanks, Nigel! I was really getting frustrated. Adding the "my" does
indeed seem to make the times independent of "newRow" and salvage the
script. However...
I am disappointed that it doesn't work as written. What is "the Serge
method"? After two days of testing different methods and timings, I had
pretty much narrowed the problem down to the "item nn of columns", but
couldn't understand what was going on. The only variable that changes
with "newRow" is that an additional item is added to the end of each
column on each iteration. In fact, you can replace the whole
"insert_item" call with
set the end of item nn of columns to item nn of valueList
and get the same result... with the same miserable performance :-(
Also, the problem doesn't seem to appear until the length of the columns
is greater than about 10 (testRows > 10). The project I am working on
requires a 40 x 90 table and at those dimensions the times are appalling.
I would be willing to just forgo knowledge of the "arcane reasons" this
works ( :-)), but I am concerned that I have now solved only _this_
problem and don't really understand how to avoid it in the future. Should
I add "my" to every property referenced in a script object?
If you can point me to a reference that explains it, I'd appreciate it.
Over all, this thing has cost me about a week of work because this
routine is central to a much larger project I am working on and if it
doesn't work, I am going to have to redesign the larger project. At first
glance, it looks like your fix has rescued it. Thanks again.
Steve
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.