WebAssembly / component-model

Repository for design and specification of the Component Model
Other
898 stars 75 forks source link

Increase the flattening limit (MAX_FLAT_RESULTS) for parameters #293

Closed orsinium closed 6 months ago

orsinium commented 6 months ago

From the current specification:

For a variety of [practical][Implementation Limits] reasons, we need to limit the total number of flattened parameters and results, falling back to storing everything in linear memory. The number of flattened results is currently limited to 1 due to various parts of the toolchain (notably the C ABI) not yet being able to express [multi-value] returns. Hopefully this limitation is temporary and can be lifted before the Component Model is fully standardized.

If I understand correctly, the only limitation is that C ABI doesn't support multi-value returns. However, it doesn't affect function parameters since complex function parameters are simply flattened into more arguments. For example, a: (i8, i8) is flattened into a.0: i8, a.1: i8.

Suggestion: Increase the flattening limit (MAX_FLAT_RESULTS) to at least 2 for parameters but not return values.

Pros: This will save quite a bit of memory roundtrips for many types, especially strings.

Cons: It will require the code to produce two slightly different representations for the same type, depending on if it is parameter or return value.

lukewagner commented 6 months ago

I might be missing your point, but there is indeed already a MAX_FLAT_PARAMS that is set to 16 (it's only MAX_FLAT_RESULTS that is 1).

orsinium commented 6 months ago

You're right! Sorry, I didn't read carefully.