Script slowing down - suggestions?
Script slowing down - suggestions?
- Subject: Script slowing down - suggestions?
- From: Martin Crisp <email@hidden>
- Date: Thu, 7 Mar 2002 10:16:56 +1100
- Organization: Tesseract Computing
Hi all,
I'm working on an applet that I want to move to C++ but am prototyping
in AppleScript. In doing so I've encountered a 'feature' that I'd like
to find a solution to in case it impacts stuff I generally do in
AppleScript.
The feature is, as the subject suggests, that the applet takes longer
and longer to do the 'same' tasks. Perhaps related is a tendency for
memory use to increase slowly over time.
The applet is a genetic algorithm which will (hopefully) find a
reasonable general solution for a game (a 2-4 player poker variant). It
only uses one 3rd party scripting addition (Acme Script Widgets, for
string<->list manipulation) and the Finder. I'm running MacOS 9.2.2,
CarbonLib1.5 and using Script Editor 1.7, on a 400MHzG4.
The applet loads several compiled scripts (once), one of which loads a
compiled script of its own (every time it is called). It also creates
'players' (text files) which include simple scripts (about 30
if<conjunction>then<action>else<action>statements). One of the compiled
scripts deals cards to a group of players, and these players' scripts
manipulate the cards by calling routines in the applet, as do the
compiled scripts themselves. Another of the compiled scripts evaluates
the resulting hands determining which players should be paid (or fined)
by the applet.
One run through the entire population (less 1 player, sometimes) is
followed by a 'breeding season' in which the 'fittest' players reproduce
to produce new players. And then the whole thing repeats. Each of these
'generations' is logged to a separate file in the Finder.
In an attempt to ensure that other applications weren't interfering with
timings I ran it overnight in the foreground with only the finder open.
The results were:
Gen. Start Pop. End. Pop. Breeders Log Size (k) Time taken (min)
958 99 91 4 216 23
959 95 94 3 184 21
960 96 88 8 188 31
961 96 93 2 212 31
962 95 87 6 220 44
963 93 89 3 212 46
964 91 85 2 216 54
965 87 82 9 156 61
966 90 85 5 208 70
Every 2 breeders produce 2 offspring (so 9 breeders produce 8 'young'),
a player 'dies' when it has insufficient money (=fitness) to keep
playing.
'Obviously' the larger the population, and the larger the number of
breeders the longer a generation will take. But a factor of almost 3
increase, over the course of 9 generations is less than desirable. [And
on past experience, although perhaps with interactions from other
applications, the time continues to balloon out. To the point where a
generation may take 2+ hours to complete]. This slowdown seems to be
general rather than in one particular section of code.
The scripts (5) total 360k. So I won't post them to the list (though if
someone desperately wants to look I can mail them...). But I'm only
after general suggestions at this point.
So, after all that, my question is: What causes AppleScript to slow to
this extent? Is it the number of interactions with the Finder (the log
file is constantly being opened & closed, as are the player files)? Or
is it the 'second-level' loading of compiled scripts? Or something else?
[I asked a related question but more to do with memory usage in
alt.comp.lang.applescript about a month ago, but the crashing I was
experiencing then seems to be more to do with other applications
running...]
Thanks in adnvance for any suggestions.
Have Fun
Martin
--
I have absolutely no reason to complain about "success" with my work;
[...] And yet, from time to time a boundless sense of inferiority
plagues me, a desperate feeling of general failure; how does a person
acquire such bits of lunacy?
- MC Escher
Almost always SMASHed
_______________________________________________
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.