Skip to content
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

Optimize emscripten targets with emcc #36899

Closed
brson opened this issue Oct 1, 2016 · 4 comments
Closed

Optimize emscripten targets with emcc #36899

brson opened this issue Oct 1, 2016 · 4 comments
Labels
E-help-wanted Call for participation: Help is requested to fix this issue. O-emscripten Target: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL! O-wasm Target: WASM (WebAssembly), http://webassembly.org/

Comments

@brson
Copy link
Contributor

brson commented Oct 1, 2016

With today's asmjs and wasm targets, we optimize the LLVM IR ourselves, and pass that IR to emcc. emcc has its own optimization options though, including but not limited to LLVM's optimization passes, so we should probably leave all optimizations to emcc. Likewise LTO should be delegated to emscripten.

So we need to change the backend to treat these targets as unoptimized in LLVM, and instead pass the optimization arguments to emcc during the "link" step. This may involve adding new features to the target spec, or possibly just special casing emscripten in the backend.

@brson brson added the E-help-wanted Call for participation: Help is requested to fix this issue. label Oct 1, 2016
@brson
Copy link
Contributor Author

brson commented Oct 1, 2016

Some optimization levels in emcc seem to disable exception handling, so we might need to be careful about exactly what we're telling emcc to do.

@Thinkofname
Copy link

-s DISABLE_EXCEPTION_CATCHING=0 can be used to re-enable that although i'm not sure if we need that? I haven't seen a case where it comes up when i've been playing around.

@brson
Copy link
Contributor Author

brson commented Oct 1, 2016

Actually we do need to continue optimizing our IR. emcc won't do it for us.

@DemiMarie
Copy link
Contributor

@Thinkofname Emscripten's current handling of exceptions is horrendous: it injects a try/catch block into almost every function. V8's optimizing compiler bails out on try/catch and other JS engines don't do well either.

So you basically need to disable LLVM-level exception handling if you want good performance on emscripten.

Fortunately, I believe (not tested!) that a workaround exists: lower panic to a call to a helper function (written in ordinary JS) that throws an exception, and lower recover to a helper function (again handwritten in ordinary JS) taking a callback.

This is really an Emscripten bug. Perhaps someone could write a patch?

@brson brson added O-asmjs Target: asm.js - http://asmjs.org/ O-wasm Target: WASM (WebAssembly), http://webassembly.org/ labels Dec 31, 2016
RReverser added a commit to RReverser/rust that referenced this issue Feb 7, 2017
It claims to accept most GNU linker options, but in fact most of them
have no effect and instead it requires some special options which are
easier to handle in a separate trait.

Currently added:
 - `export_symbols`: works on executables as special Emscripten case
since staticlibs/dylibs aren't compiled to JS, while exports are
required to be accessible from JS.
Fixes rust-lang#39171.
 - `optimize` - translates Rust's optimization level to Emscripten
optimization level (whether passed via `-C opt-level=...` or `-O...`).
Fixes rust-lang#36899.
 - `debuginfo` - translates debug info; Emscripten has 5 debug levels
while Rust has 3, so chose to translate `-C debuginfo=1` to `-g3`
(preserves whitespace, variable and function names for easy debugging).
Fixes rust-lang#36901.
 - `no_default_libraries` - tells Emscripten to exlude `memcpy` and co.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 8, 2017
Add Emscripten-specific linker

Emscripten claims to accept most GNU linker options, but in fact most of `-Wl,...` are useless for it and instead it requires some additional special options which are easier to handle in a separate trait.

Currently added:
 - `export_symbols`: works on executables as special Emscripten case since staticlibs/dylibs aren't compiled to JS, while exports are required to be accessible from JS.
Fixes rust-lang#39171.
 - `optimize` - translates Rust's optimization level to Emscripten optimization level (whether passed via `-C opt-level=...` or `-O...`).
Fixes rust-lang#36899.
 - `debuginfo` - translates debug info; Emscripten has 5 debug levels while Rust has 3, so chose to translate `-C debuginfo=1` to `-g3` (preserves whitespace, variable and function names for easy debugging).
Fixes rust-lang#36901.
 - `no_default_libraries` - tells Emscripten to exclude `memcpy` and co.

TODO (in future PR): dynamic linking via `SIDE_MODULE` / `MAIN_MODULE` mechanism.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Feb 8, 2017
Add Emscripten-specific linker

Emscripten claims to accept most GNU linker options, but in fact most of `-Wl,...` are useless for it and instead it requires some additional special options which are easier to handle in a separate trait.

Currently added:
 - `export_symbols`: works on executables as special Emscripten case since staticlibs/dylibs aren't compiled to JS, while exports are required to be accessible from JS.
Fixes rust-lang#39171.
 - `optimize` - translates Rust's optimization level to Emscripten optimization level (whether passed via `-C opt-level=...` or `-O...`).
Fixes rust-lang#36899.
 - `debuginfo` - translates debug info; Emscripten has 5 debug levels while Rust has 3, so chose to translate `-C debuginfo=1` to `-g3` (preserves whitespace, variable and function names for easy debugging).
Fixes rust-lang#36901.
 - `no_default_libraries` - tells Emscripten to exclude `memcpy` and co.

TODO (in future PR): dynamic linking via `SIDE_MODULE` / `MAIN_MODULE` mechanism.
RReverser added a commit to RReverser/rust that referenced this issue Feb 10, 2017
It claims to accept most GNU linker options, but in fact most of them
have no effect and instead it requires some special options which are
easier to handle in a separate trait.

Currently added:
 - `export_symbols`: works on executables as special Emscripten case
since staticlibs/dylibs aren't compiled to JS, while exports are
required to be accessible from JS.
Fixes rust-lang#39171.
 - `optimize` - translates Rust's optimization level to Emscripten
optimization level (whether passed via `-C opt-level=...` or `-O...`).
Fixes rust-lang#36899.
 - `debuginfo` - translates debug info; Emscripten has 5 debug levels
while Rust has 3, so chose to translate `-C debuginfo=1` to `-g3`
(preserves whitespace, variable and function names for easy debugging).
Fixes rust-lang#36901.
 - `no_default_libraries` - tells Emscripten to exlude `memcpy` and co.
bors added a commit that referenced this issue Feb 10, 2017
Add Emscripten-specific linker

Emscripten claims to accept most GNU linker options, but in fact most of `-Wl,...` are useless for it and instead it requires some additional special options which are easier to handle in a separate trait.

Currently added:
 - `export_symbols`: works on executables as special Emscripten case since staticlibs/dylibs aren't compiled to JS, while exports are required to be accessible from JS.
Fixes #39171.
 - `optimize` - translates Rust's optimization level to Emscripten optimization level (whether passed via `-C opt-level=...` or `-O...`).
Fixes #36899.
 - `debuginfo` - translates debug info; Emscripten has 5 debug levels while Rust has 3, so chose to translate `-C debuginfo=1` to `-g3` (preserves whitespace, variable and function names for easy debugging).
Fixes #36901.
 - `no_default_libraries` - tells Emscripten to exclude `memcpy` and co.

TODO (in future PR): dynamic linking via `SIDE_MODULE` / `MAIN_MODULE` mechanism.
@workingjubilee workingjubilee added O-emscripten Target: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL! and removed O-asmjs Target: asm.js - http://asmjs.org/ labels Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-help-wanted Call for participation: Help is requested to fix this issue. O-emscripten Target: 50% off wasm32-unknown-musl. the savings come out of stdio.h, but hey, you get SDL! O-wasm Target: WASM (WebAssembly), http://webassembly.org/
Projects
None yet
Development

No branches or pull requests

4 participants