Skip to content

Conversation

@fitzgen
Copy link
Member

@fitzgen fitzgen commented Feb 10, 2026

Do not hold regular Strings; instead use our own OOM-handling
wasmtime_core::alloc::String or, even better, an interned Atom from the
StringPool.

Also avoid IndexMap, as it doesn't handle OOMs.

Depends on

Do not hold regular `String`s; instead use our own OOM-handling
`wasmtime_core::alloc::String` or, even better, an interned `Atom` from the
`StringPool`.

Also avoid `IndexMap`, as it doesn't handle OOMs.
@fitzgen fitzgen requested review from a team as code owners February 10, 2026 22:18
@fitzgen fitzgen requested review from cfallin and removed request for a team February 10, 2026 22:18
@alexcrichton
Copy link
Member

Knee-jerk reaction before you have too many more PRs that depend on this -- IndexMap is 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 of IndexMaps throughout compilation/etc. Is the usage pretty localized to just one or two locations though?

@fitzgen
Copy link
Member Author

fitzgen commented Feb 10, 2026

Knee-jerk reaction before you have too many more PRs that depend on this -- IndexMap is 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 of IndexMaps throughout compilation/etc. Is the usage pretty localized to just one or two locations though?

IndexMap is either index_map::IndexMap or a BTreeMap depending on wasmparser configuration:

pub use wasmparser::collections::{IndexMap, IndexSet};

std/alloc does not provide a way to fallibly reserve/insert/allocate for BTreeMaps.

And index_map::IndexMap does not provide a try_reserve method either. Additionally, index_map::IndexMap's Deserialize implementation requires that the key be Clone, which our OOM-handling Strings are most definitely not.

So it seems like continuing to use IndexMap is going to be an uphill battle.

We could make our own IndexMap that 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 with exports here is basically inlining/hard-coding one specific instance of that?

Thoughts?

@alexcrichton
Copy link
Member

One possible fix might be to use indexmap::IndexMap (directly from the crate, not wasmparser). That should support no_std and it looks like it's got a try_reserve to work for us as well. For Deserialize wouldn'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::IndexMap wrapper the same way we have a Vec wrapper and then replace the usage of wasmparser::IndexMap with that fallible IndexMap.

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator wasmtime:api Related to the API of the `wasmtime` crate itself labels Feb 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cranelift Issues related to the Cranelift code generator wasmtime:api Related to the API of the `wasmtime` crate itself

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants