Wasm with GLFW + OpenGL

325 views
Skip to first unread message

Ulhas Pawar

unread,
Jan 16, 2023, 10:42:57 AM1/16/23
to emscripten-discuss
Hello,
Need your help understaning how JS code is generated.

In my project, I am using Emscripten to generate WASM. For window management, I am using GLFW window. Application is working fine.
But generated JS code contains lot of unnecessary DOM manipulations and event binding not used in application.
What I wanted is simple display-only canvas, but generated code is handling lot of events I do not need. This also causing some leakage issues in handlers.

Is there any way I can get rid of this code? Some compilation options or why it is present at first place?

Any pointers would help.

Thanks,
Ulhas

Sam Clegg

unread,
Jan 16, 2023, 10:48:22 AM1/16/23
to emscripte...@googlegroups.com
On Mon, Jan 16, 2023 at 7:42 AM Ulhas Pawar <ulhas...@orbo.ai> wrote:
Hello,
Need your help understaning how JS code is generated.

In my project, I am using Emscripten to generate WASM. For window management, I amny way I can get rid of this code? Some compilation options using GLFW window. Application is working fine.
But generated JS code contains lot of unnecessary DOM manipulations and event binding not used in application.
What I wanted is simple display-only canvas, but generated code is handling lot of events I do not need. This also causing some leakage issues in handlers.

Is there any way I can get rid of this code? Some compilation options or why it is present at first place?

Can you give some specific examples of symbols/functions that are not being used that are being included? 

It could just be the way that the GLFW library is structured that makes it hard to perform dead code stripping.

Are you building with `-Oz` or `-Os` (these do the most aggressive dead code stripping).. also have you tried `--closure=1`?

cheers,
sam
 

Any pointers would help.

Thanks,
Ulhas

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/e857903d-eb2d-49ed-be08-3accc11514d7n%40googlegroups.com.

Floh

unread,
Jan 18, 2023, 5:36:26 AM1/18/23
to emscripten-discuss
Are you building will all optimization options turned to 11? Usually Emscripten is very good at aggressive dead code elimination, both on the WASM and JS side. Some things to check in the build settings to minimize build size (I'm not 100% sure how many of those are still needed versus having become the default now):

- turn off filesystem support if you don't need it: -s NO_FILESYSTEM=1 (linker setting)
- enabling LTO may help with more aggressive DCE, but also causes more aggressive inlining: -flto (compile and linker setting)
- enable the Closure JS minifier: --closure (linker setting)
- enable minimal runtime -s MINIMAL_RUNTIME=2 -s ENVIRONMENT=web
- test the various optimization settings that trade off speed vs size (-O2 vs -Os vs -Oz)

Finally if you are looking for a more minimal GLFW/SDL replacement, check out sokol_app.h. This has fewer features than GLFW or SDL for desktop platforms, but is a fairly complete alternative for WASM applications:


Cheers!

Floh

unread,
Jan 18, 2023, 5:40:34 AM1/18/23
to emscripten-discuss
PS: if you don't allocate/free with very high frequency, also consider switching to the minimal Emscripten allocator with "-s MALLOC='emmalloc'"

Floh

unread,
Jan 18, 2023, 5:42:11 AM1/18/23
to emscripten-discuss
PPS: closure linker setting is actually "--closure 1".
Reply all
Reply to author
Forward
0 new messages