Only persist context when maestro or output binding modified
Proposed changes
Graal JS contexts take almost a full 1MB of memory, and if we have a repeated loop of commands, we can easily hit 1000+ commands (with associated contexts). The contexts are only cleared when the full maestro flow is done executing, which means we can bloat our memory considerably.
However, if we close a context, then values that have been stored on our output or maestro objects will get wiped. So we need to keep those values around.
This PR immediately closes contexts only when we detect that the the bindings have not been updated. Otherwise we keep the context around until the engine is closed.
Testing
See test suite to understand how this was tested.
NOTE
This fix relies on the fact that all callers of evaluateScript cast the result to a string. It would probably be safer to force the return type of this to String instead of Any; we have to do that because we need to copy the Value returned by the js engine to a kotlin type. There might be a better solution, but I didn't want to touch too much code around this.
Oooh, I wonder how this affects runs inside Studio? I wonder if this helps with #1087