Skip to content

Allow custom wasm malloc implementation #3245

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

anuraaga
Copy link
Contributor

@anuraaga anuraaga commented Oct 21, 2022

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.

@anuraaga
Copy link
Contributor Author

@dgryski @aykevl would it be possible to get a review on this? Thanks!

Copy link
Member

@dgryski dgryski left a comment

Choose a reason for hiding this comment

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

LGTM; this is only shuffling around some code and adding build tags.

@deadprogram
Copy link
Member

Thanks for the improvement @anuraaga and to @dgryski for review. Now going to squash/merge.

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