-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Automatic INITIAL_MEMORY
for statically large modules
#20888
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
Comments
The problem I suppose is the I guess for most folks this isn't a huge issue since most programs don't tend to have a lot of static data. 16mb of static data is fairly unusual I think. Would |
My initial thought was a way to simply not pass anything (effectively, initial heap size of zero). Allowing one to configure the initial heap size on top of that would be an optimization - how significant is it?
That's true, the motivation here is removing the (unnecessary) complexity from the toolchain. |
Sadly this won't work without some other changes since we default to a non-growable memory. Most programs would not work with a heap size of zero.
Are you referring to existing complexity in emscripten? Or in the .NET toolchain? |
Ah, I assume you are referring to the referring guesstimate code that you linked to above. I agree that should really not be necessary. |
Would making this only supported with |
Sure, I think making this work for But the default setting is But defaulting to simply not passing |
I will work on the full |
Emscripten uses tip of tree llvm. We integrate changes right away. |
It is beneficial to preallocate a certain number of pages in the linear memory (i. e. use the "minimum" field of WASM memories) so that fewer "memory.grow"s are needed at startup. So far, the way to do that has been to pass the "--initial-memory" option to the linker. It works, but has the very significant downside of requiring the user to know the size of static data beforehand, as it must not exceed the number of bytes passed-in as "--initial-memory". The new "--initial-heap" option avoids this downside by simply appending the specified number of pages to static data (and stack), regardless of how large they already are. Ref: emscripten-core/emscripten#20888.
@sbc100 I've drawn up the design sketch for the Emscripten side of this work:
Does it look good to you? As |
This sounds good to me. I think we could probably also deprecate INITIAL_MEMORY at some point since it seems strictly better to use |
The llvm change should now be available in emscripten, of you would like a set a PR here. |
Yep, working on it. It turns out there are a few places that rely on |
I wonder if we could just make Alternatively we just deprecate |
There is a significant difference between the two settings: Here's the current version of the changes, I think it illustrates the differences: https://github.com/emscripten-core/emscripten/compare/main...SingleAccretion:emscripten:Initial-Heap?expand=1. I still need to fix up the case where
It is certainly possible to make breaking changes. |
It is beneficial to preallocate a certain number of pages in the linear memory (i. e. use the "minimum" field of WASM memories) so that fewer "memory.grow"s are needed at startup. So far, the way to do that has been to pass the "--initial-memory" option to the linker. It works, but has the very significant downside of requiring the user to know the size of static data beforehand, as it must not exceed the number of bytes passed-in as "--initial-memory". The new "--initial-heap" option avoids this downside by simply appending the specified number of pages to static data (and stack), regardless of how large they already are. Ref: emscripten-core/emscripten#20888.
Right now the default value of
INITIAL_MEMORY
is 16MB, which sets a hard limit on the amount of static data in a module - the linker will error out if the amount is insufficient. To work around this, you need to be able to calculate the number beforehand, e. g. the official .NET SDK guesstimates by doing something to the effect of going over all of the inputs and summing their size.This all seems rather self-inflicted. The linker already knows how much memory will it need, and indeed, if you don't pass
--initial-memory
, it will already "do the right thing".The question is, can this automatic behavior be supported by Emscripten natively?
Note: this is all assuming memory growth is allowed, of course.
The text was updated successfully, but these errors were encountered: