Skip to content

Conversation

@DenKoren
Copy link
Contributor

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)

@DenKoren DenKoren changed the title Add ability to replace builtin modules in compiled code Replace builtin modules in compiled code Dec 11, 2025
@DenKoren DenKoren changed the title Replace builtin modules in compiled code Replace builtin modules in compiled script Dec 11, 2025
@geseq
Copy link
Collaborator

geseq commented Dec 13, 2025

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?

Copy link
Collaborator

@geseq geseq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall

return nil
}

func (c *Compiled) prepareForModulesUpdate() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants