Skip to content

Why vJass function interfaces aren't used

Son Guhun edited this page Sep 12, 2020 · 1 revision

vJass function interfaces are pretty cool. They give you a nice syntax to work with, when compared to how you would normally handle using functions as arguments.

They also don't create that many extra variables. Each function interface creates: 1 global array, which holds triggers. 1 caller function, which executes a trigger in that array and sets the values of globals to its arguments. Additionally, it will create extra global variables to pass the arguments and receive return values. However, these will only be created if they are needed. If you have two interfaces which have only 1 boolean among their arguments, then only one boolean global will be created. However, if you create a third interface which has two booleans in its arguments, then a new boolean global will be created.

Then, for each function cast to that interface, a new function will be created, which will be the action/condition of the trigger that will get executed when the function is evaluated. This function's body does not call the original function, it instead copies the entire body of the original. That means, if you never call the original function, only evaluate it, then the original function will be removed during the optimization phase, because it is unused. This means that new functions which use a interface will NOT create any new variables. The only things that will be created are a trigger, a triggeraction, a triggercondition and a boolexpr.

So in general, function interfaces are not that heavy, and using them is a pretty good idea. However, for Titan Land LoP, we want to optimize the code as much as possible, since JASS is already a pretty slow language. Therefore, a new syntax was created as a replacement for function interfaces.


The advantages of the FuncInterface library are:

  • Only a single global variable is created.
  • No new functions are created when a new Interface is declared, unless the user decides to the the evaluate function instead of the evaluate textmacro.
  • No triggers are created for evaluating the functions

Disadvantges include:

  • API that is harder to work with and that can be more easily misused.
  • A bit slower than normal function interfaces, though the amount is negligible in most cases in which function interfaces would be used.

Normally it would not be a good idea to perform this type of premature optimization. However, in the specific case of JASS (a slow and not very flexible language) and this map, I determined that it would be the better alternative than trying to fix performance issues in the future.