Allow builtin modules replacement in compiled scripts #454
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation:
Compiled scripts can be executed concurrently out of the box.
At the same time, custom builtin modules can be passed to tengo script out from go, providing additional functionalities to the script.
If such builtin module is not designed for concurrent use, it becomes a limitation for the compiled tengo script. In most cases it is possible to 'rule out' concurrency use limitation on module's side, but in most cases this is 'fixed' by new lock introductions, which makes parallel tengo compiled scripts execution to block on single instance of builtin module during runtime.
For now, the only way to overcome this issue is to re-compile template for each instance of builtin module, which 8000 works well but leads to code overcomplication: it becomes necessary to manage compiled script pools in order to execute each script instance solely single-threaded because it is strictly bound to single builtin module instance.
This feature allows to hot-swap builtin module instance inside compiled script making it possible to execute several clones (
.Clone()
) in parallel, each using its own instance of builtin module.