Replace builtin modules in compiled script#473
Open
Conversation
Conflicts: bytecode.go
test: concurrent test for ReplaceBuiltinModule
Collaborator
|
Thanks for the PR. This looks like a good idea overall. On a high level this looks good to me, but will review deeper today/tomorrow. @d5 can you take a look as well please? |
geseq
requested changes
Dec 29, 2025
| return nil | ||
| } | ||
|
|
||
| func (c *Compiled) prepareForModulesUpdate() { |
Collaborator
There was a problem hiding this comment.
I would just inline this into ReplaceBuiltinModule or lock the mutex here. Otherwise someone has to remember to lock correctly if they were reusing this function in the future
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Compiled code can be executed concurrently out of the box thanks to
Clone()method of compiled script.The problem is that custom builtin module, given to the script as a 'dependency' may not support this. Or it may require customisation for each clone to work properly (say, you provide a driver, transaction, connection or whatever else that should be unique for each script).
Inability to update/replace builtin modules inside script after compilation makes it impossible to re-use compiled script and requires compilation for each run.
This PR solves the mentioned limitation by extending compiled script's API.
The change is implemented maintaining backward compatibility with old behaviour, where bytecode was shared across several cloned instances of script.
Bytecode gets copied only when builtin modules need to be replaced after compilation (kind of 'copy-on-write' approach)