Allow custom wasm malloc implementation #3245
Merged
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.
This moves the existing code for overriding malloc for wasm into a separate file with a
custommalloc
build tag defined to allow excluding it. This allows apps to bring their own malloc for wasm.I could confirm that with this change, I could swap malloc with mimalloc and then also swap the GC to one that uses malloc for the underlying heap instead of taking full ownership.
https://github.com/corazawaf/coraza-proxy-wasm/compare/main...anuraaga:mimalloc?expand=1
This dramatically improves performance of the polyglot Envoy wasm filter, bringing pauses from ~1s to ~100ms, and also gives me a playground to make more changes to the GC that aren't "tiny" :) Note that the current GC may be improvable - I tried playing with
isPointerlike
to have it recognize malloc'd pointers as not Go objects, and didn't have much performance difference but may have not finished it properly. Either way, we would expect it to be significantly better to have malloc'd objects outside of the Go GC completely anyways.This would also resolve the issue in #3162 - no problem making the default malloc tiny and possibly
O(n)
if it can be replaced easily.