Are there any common tips (read: design patterns) that would help the performance of a long-running script? I mean, without a specific case, some general tips.
For example, when looping over layers, it's better not to query the number of layers at each iteration.
That is,
for (var i = 0, len = set.layers.length; i < len; i++) { .... }
is faster than
for (var i = 0; i < set.layers.length; i++) { ... }
That's a simple optimization off the top of my head.