Technical tips to keep processing time down

I know there’s a general obligation to keep complexity low in Vassal modules, and that involves some basic principles like not having too many traits, carefully defining GKC targets, and avoiding overly-long ? : constructions in trigger conditions, for example.

But sometimes I seem to go over the complexity budget, but find the features I added too useful to do without, and then I can end up in very time-consuming testing to find out what exactly takes the most time and how to try and make slow functions milliseconds or even whole seconds faster.

So I was wondering if there were any more principles of module design I could apply to alleviate the need for such testing. Things that might be obvious to a real programmer, or someone with detailed knowledge of Vassal’s code, but might not be obvious to someone who has only ever interacted with the Vassal editor UI.

For example, say you have a map-level key command that can trigger all kinds of things on piece move. Say a trigger has a bunch of conditions to ensure it only fires under specific circumstances. Does it matter if you put the “simplest” condition to not trigger “first” in the beanshell line? Does a conditional restriction trait work faster/better under some circumstances?

Any and all tips welcome (other than “use custom code” - I’d like to keep everything inside Vassal). It’s hard for me to speculate about what might be beneficial, because I don’t have a good idea of the scope of what I don’t know…

Workarounds include:

Simplify GKC Match Expression, number of properties referenced and change all IF() to ?:
Use Fast Match carefully to find a smaller set of pieces to apply the complex match to
Avoid referencing Calculated properties in the GKC Expressions, or in any CP’s referenced by the GKC Expression.
Avoid Calculated properties referencing other Calculcated Properties in general.
Avoid Calculated Properties in ‘Layer Follows property’ Expressions
If possible, Move the traits that contain the properties that are referenced by the GKC Expression down to the bottom of the trait list.
Avoid using the Count() and Sum() and related functions as these are essentially GKC’s.

Copy-pasting some useful tips from Brent here for my own and others’ reference.

Perhaps make a post in the Documentation sub-forum - and make sure to make it a Wiki-post - with these tips in, and then link it from the Documentation Index under the appropriate heading - e.g., Module development→Miscellaneous - as f.ex. How to speed up modules - various tips.

That will make the advice more permanent and easier to find.

Yours,
Christian