This is a simple one in concept. We do this all the time at ISW manually, and it's a pain that the compiler can't do it automatically, especially considering it automatically does it for taskfuncs anyway.
The idea:
function foo(age, height, weight) -> result
// function body FOO here
result := // something returned
end function
should be preprocessor compiled to:
function foo(age, height, weight) -> result
sksp.foo.args.age := age
sksp.foo.args.height := height
sksp.foo.args.weight := weight
call _foo
result := sksp.foo.return
end function
function _foo
declare local age := sksp.foo.args.age
declare local height := sksp.foo.args.height
declare local weight := sksp.foo.args.weight
// function body FOO here
sksp.foo.return := // something returned
end function
if and only if the number of lines inside the original foo is greater than roughly the number of arguments + optional return + 1 (for the call).
For example here with 3 args, 1 return, and 1 call, function foo should be at least 5 lines for this optimization to have been worth it, line-count wise, as all invocations of foo now become this static 5-line invocation instead.
This promotes proper code re-use inside Kontakt scripts and reduces massive compile line counts without laborious refactoring of existing codebases or expanding codebases where functions that didn't need line optimization now do after extending the featureset.
This is a simple one in concept. We do this all the time at ISW manually, and it's a pain that the compiler can't do it automatically, especially considering it automatically does it for taskfuncs anyway.
The idea:
should be preprocessor compiled to:
if and only if the number of lines inside the original
foois greater than roughly the number of arguments + optional return + 1 (for thecall).For example here with 3 args, 1 return, and 1 call, function
fooshould be at least 5 lines for this optimization to have been worth it, line-count wise, as all invocations offoonow become this static 5-line invocation instead.This promotes proper code re-use inside Kontakt scripts and reduces massive compile line counts without laborious refactoring of existing codebases or expanding codebases where functions that didn't need line optimization now do after extending the featureset.