Skip to content

Testing a single context, IIFE-based approach to isolating vars set i…#2886

Merged
amanjeetsingh150 merged 3 commits intomainfrom
isolate-context-through-iife
Mar 17, 2026
Merged

Testing a single context, IIFE-based approach to isolating vars set i…#2886
amanjeetsingh150 merged 3 commits intomainfrom
isolate-context-through-iife

Conversation

@steviec
Copy link
Collaborator

@steviec steviec commented Dec 12, 2025

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 keeps a single, shared context, which guarantees that output and maestro objects persist across invocations. It uses IIFE to isolate vars defined in the user script, and has to do additional management of the dynamic env vars to maintain our sub scope logic.

Testing

See test suite to understand how this was tested. The tests are identical to the other PR: #2881.

Comment on lines +148 to +152
// Clear non-permanent (env) bindings, then set current env vars
bindings.memberKeys
.filter { it !in permanentBindingKeys }
.forEach { bindings.removeMember(it) }
envBinding.forEach { (k, v) -> bindings.putMember(k, v) }
Copy link
Collaborator Author

@steviec steviec Dec 15, 2025

Choose a reason for hiding this comment

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

Note that this would be much cleaner if we just made ENV variables available on a named binding for it, e.g. env instead of putting them directly on the context root.

@amanjeetsingh150 amanjeetsingh150 force-pushed the isolate-context-through-iife branch from 3150718 to e365c98 Compare March 17, 2026 05:20
@amanjeetsingh150 amanjeetsingh150 merged commit 692adb7 into main Mar 17, 2026
9 checks passed
@amanjeetsingh150 amanjeetsingh150 deleted the isolate-context-through-iife branch March 17, 2026 05:46
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.

3 participants