-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Support for fast startup by restoring pre-initialized memory #15402
Comments
We have setting called Lines 1540 to 1575 in bbc208c
However, this settings I believe was disabled with under the upstream llvm backend and needs to be revived and re-enabled. As for more advanced versions of snapshotting and I think best hope would be integration with something like https://github.com/bytecodealliance/wizer. |
It was disabled at some point due to integration with malloc/sbrk, #9527 Those are no longer an issue, so it could be revived if it's useful. And extending it to do work in The reason I haven't focused on it myself is that the benefit usually comes with a tradeoff in larger size, and I wasn't aware of current use cases. I could try to find time though if it seems like it could be useful? |
If setting EVAL_CTORS will disable the emscripten logic that interferes, we may be able to do the rest ourselves. I'll let you know if we start testing it out and hit anything, we last attempted this mid-2020 and hit roadblocks then. |
I'm not sure what you mean by "disable the emscripten logic that interferes" but I don't think EVAL_CTORS effects the generated code at all. All it does it take a wasm file an produce anther wasm file that does potentially less work at startup, and it has fairly limited powers... IIRC its mostly able to remove static constructors that do just set memory locations and not much else. |
I opened #15403 to test if we can re-enable that option. I believe it should safe now (as @sbc100 noted in #9527 (comment), we don't dynamically allocate in JS, and sbrk is now 100% in wasm, etc.), and the one known failure does pass for me locally. |
Heads up that I'll be looking into this soon. I've identified what I think are the main issues preventing this from working well now, and I intend to work on them in the coming weeks. |
PR open: #16011 |
This updates us to use Binaryen's new version of wasm-ctor-eval, which can now do a lot more things, like eval just part of a function, eval to globals, etc. That plus other changes on the emscripten side that move more things like sbrk into pure wasm means that we can eval a lot more code. Previously -Oz would enable EVAL_CTORS. That was pretty dangerous as often it does not help code size. You really just need to run with the option and then measure the code size change vs the startup speed improvement. So this PR makes us no longer do anything automatically - you must manually build with -s EVAL_CTORS. A new mode EVAL_CTORS=2 is also added. This enables wasm-ctor-eval's new --ignore-external-input flag, which ignores the environment, params to main, etc. This is unsafe, and probably we should have separate options for these things, but for now this seems useful for experimentation. Tested by running all of wasm2 with EVAL_CTORS=2 enabled, and then ignoring the failures that are expected (things reading from argv, for example). Also I ran around 200,000 fuzzer iterations on binaryen. Example results on ./emcc tests/hello_libcxx.cpp -O3: mode | wasm size (bytes) --------------+------------------ normal | 136625 EVAL_CTORS-1 | 136616 EVAL_CTORS-2 | 133059 The output on the last one is: trying to eval __wasm_call_ctors ...success on __wasm_call_ctors. trying to eval main ...partial evalling successful, but stopping since could not eval: call import: wasi_snapshot_preview1.fd_write ...stopping It completely evals the ctors, and in main it evals some stuff, until it reaches a call to print to stdout. Fixes #15402
For WASM applications it's theoretically feasible to generate a full heap offline and then do fast application startup by loading that data directly into memory at startup instead of running lots of init code. Is this something that emscripten could be made compatible with? Right now things like C++ constructors and the VFS seem to assume that an application is always being started fresh and there's no obvious way to adjust everything so that this could work.
The text was updated successfully, but these errors were encountered: