Brittgriscom wrote:
If that's the routine that ran slowly, it may be helpful to see the entire handler. The sort command is implemented internally in reasonably efficient C++, so aside from the modest overhead of packaging up the data to hand off to it, it's likely not the source of performance issues.
The main culprit, as I said, is the function above, which seeks to match each new board state with every previous board state. I'm actually considering leaving it out.
Ah, I had misunderstood. I'll see if I can get some time to look into that later today, but offhand I can see a couple things that can boost performance dramatically:
1. Using "repeat for each..." is much faster than using "repeat with i =...", and avoiding "get line <lineNumber>..." within a loop can be very helpful as well, for the reasons described here:
http://lists.runrev.com/pipermail/use-l ... 19032.html
2. Accessing data in fields is much slower than accessing data in a variable. For a long but hopefully enjoyable metaphor explaining why this is the case, this may be a fun read:
http://lists.runrev.com/pipermail/use-l ... 11478.html
Also, this article offers general tips on measuring performance:
http://livecodejournal.com/tutorials/be ... vtalk.html
@ is used when passing a variable by reference; without it, variables as passed by value.
What is the difference?
Passing by value copies the contents of the variable into the parameter of the receiving handler, so the data the receiving handler works on is a duplicate, leaving the original data in the calling handler untouched. Passing by reference uses a pointer to the original data, so the receiving handler is working on the same original data. Both are useful, but in different circumstances.
If you're going to be altering the data to extract a new value (such as one might do in crafting a pull-parser, which chops items off the front as it goes) and you'll still need the original data in the calling handler for other operations, passing by value is ideal.
But if the handler being called will be returning the data in a modified form and you want to use that modified form in the calling handler, passing by reference is a simpler way to do that, so you can write "ModifyData tData" instead of "put ModifiedData(tData) into tData".
Another minor benefit to passing by reference is that when working with really large data (many MBs) it can save a little memory, since it doesn't need to make a copy of the data when passing it along to another handler.