fitzgen opened PR #12565 from fitzgen:use-oom-handling-string-in-env-module to bytecodealliance:main:
Do not hold regular
Strings; instead use our own OOM-handling
wasmtime_core::alloc::Stringor, even better, an internedAtomfrom the
StringPool.Also avoid
IndexMap, as it doesn't handle OOMs.Depends on
fitzgen requested wasmtime-compiler-reviewers for a review on PR #12565.
fitzgen requested cfallin for a review on PR #12565.
fitzgen requested wasmtime-core-reviewers for a review on PR #12565.
alexcrichton commented on PR #12565:
Knee-jerk reaction before you have too many more PRs that depend on this --
IndexMapis a relatively fundamental dependency especially for components, so I'm not sure we'll be able to escape making an OOM friendly version. Or at least I recall my impression being that we have quite a lot ofIndexMaps throughout compilation/etc. Is the usage pretty localized to just one or two locations though?
fitzgen commented on PR #12565:
Knee-jerk reaction before you have too many more PRs that depend on this --
IndexMapis a relatively fundamental dependency especially for components, so I'm not sure we'll be able to escape making an OOM friendly version. Or at least I recall my impression being that we have quite a lot ofIndexMaps throughout compilation/etc. Is the usage pretty localized to just one or two locations though?
IndexMapis eitherindex_map::IndexMapor aBTreeMapdepending onwasmparserconfiguration:
std/allocdoes not provide a way to fallibly reserve/insert/allocate forBTreeMaps.And
index_map::IndexMapdoes not provide atry_reservemethod either. Additionally,index_map::IndexMap'sDeserializeimplementation requires that the key beClone, which our OOM-handlingStrings are most definitely not.So it seems like continuing to use
IndexMapis going to be an uphill battle.We could make our own
IndexMapthat is a full implementation, rather than simply a newtype wrapper over either of those existing implementations. But that also seems pretty annoying and like more of a maintenance burden than is ideal... But maybe not, given that what I did withexportshere is basically inlining/hard-coding one specific instance of that?Thoughts?
alexcrichton commented on PR #12565:
One possible fix might be to use
indexmap::IndexMap(directly from the crate, notwasmparser). That should support no_std and it looks like it's got atry_reserveto work for us as well. ForDeserializewouldn't we be writing custom impls as opposed to using any built-in ones too?I guess what I'm saying is that my leaning is that we should have an
indexmap::IndexMapwrapper the same way we have aVecwrapper and then replace the usage ofwasmparser::IndexMapwith that fallibleIndexMap.
github-actions[bot] added the label cranelift on PR #12565.
github-actions[bot] added the label wasmtime:api on PR #12565.
fitzgen updated PR #12565.
fitzgen commented on PR #12565:
I guess what I'm saying is that my leaning is that we should have an
indexmap::IndexMapwrapper the same way we have aVecwrapper and then replace the usage ofwasmparser::IndexMapwith that fallibleIndexMap.Okay, that has been done and I've pushed a new commit that switches this back to using
IndexMapinstead of multiple{Primary,Secondary}Maps.Also this depends on these other PRs now:
fitzgen updated PR #12565.
alexcrichton submitted PR review.
alexcrichton created PR review comment:
This I think is no longer needed?
fitzgen updated PR #12565.
fitzgen has enabled auto merge for PR #12565.
fitzgen added PR #12565 Refactor String usage in wasmtime_environ::Module to the merge queue
fitzgen merged PR #12565.
fitzgen removed PR #12565 Refactor String usage in wasmtime_environ::Module from the merge queue
Last updated: Feb 24 2026 at 04:36 UTC