(fix): release workflow binary memory after use during init#21525
(fix): release workflow binary memory after use during init#21525justinkaseman wants to merge 1 commit intodevelopfrom
Conversation
|
👋 justinkaseman, thanks for creating this pull request! To help reviewers, please consider creating future PRs as drafts first. This allows you to self-review and make any final changes before notifying the team. Once you're ready, you can mark it as "Ready for review" to request feedback. Thanks! |
|
✅ No conflicts with other open PRs targeting |
|
I see you updated files related to
|
There was a problem hiding this comment.
Pull request overview
Risk Rating: MEDIUM (touches workflow engine creation path; small diff but affects startup behavior and memory/liveness characteristics)
Reduces memory retained during concurrent workflow engine initialization by clearing large binary references earlier in tryEngineCreate, so they don’t remain reachable while waiting for initDone.
Changes:
- Clear
spec.Workflow(hex-encoded binary) immediately after decoding to[]byte. - Clear
decodedBinaryafterengineFactoryreturns to shorten the lifetime of the local reference.
|
|
the spikes were observed even before introducing concurrency. still the diagnosis and the solution seems like a proper direction. it would be good to present a load-tests chart confirming smoother memory profile on reboot |


Problem
During startup all workflows are loaded concurrently (up to maxConcurrency=12 in flight simultaneously). Each goroutine calls
tryEngineCreate, which:spec.Workflow(hex-encoded compressed WASM → 2× the compressed binary size as a Go string)hex.DecodeString(decodedBinary)(the compressed binary, 1× size)engineFactorywherehost.NewModulecompiles the binary into the wasmtime engineinitDonewhile trigger subscriptions completespec.WorkflowanddecodedBinaryare both pinned intryEngineCreate's stack frame throughout the entireinitDonewaiting on trigger subscriptions (seconds per workflow).12 goroutines x 3x compressed WASM each = 36x compressed WASM pinned continuously in Go heap
This can cause problems if we are running close to the maximum workflows.
Fix
This change releases them after they are finished being used milliseconds into the 15-second window.
After each batch the GC is also prompted to clean up.