emscripten-core / emscripten-core/emscripten

Webgl 2 application compiled with emscripten "-pthread" results in extremely slow rendering on Safari 15.2

Open
#16,104 5 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
27.6k
Forks
3.6k
Avg merge
1d 1h
Merged PRs (30d)
105

Description

emscripten version: 3.1.2

Hi emscripten maintainers, thanks for the work on this incredible project. I am working on a C++ game for the web that I compile using emscripten. I recently ran into a use-case that required threading, so I began modifying my project to compile with thread support via the `-pthread` flag. These are the flags I used to compile with:

```
set(CMAKE_CXX_FLAGS "-O3 -s USE_WEBGL2=1 -s FULL_ES3=1 -s USE_GLFW=3 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -o index.html --preload-file ${project_resources} --use-preload-plugins -s ASSERTIONS=1")
```

This is what I switched to in order to enable thread support:

```
set(CMAKE_CXX_FLAGS "-O3 -s USE_WEBGL2=1 -s FULL_ES3=1 -s USE_GLFW=3 -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -pthread -o index.html --preload-file ${project_resources} --use-preload-plugins -s ASSERTIONS=1")
```

This results in a build that runs perfectly fine in Firefox and Chrome, but for some reason in Safari 15.2 (the latest version) it leads to my rendering code taking over 20 seconds to put out a single frame. I don't have any threading code implemented yet - simply compiling the project with `-pthread` results in the enormous performance penalty.

Before I go and try to create a minimal reproducible build, does anybody have any ideas as to what might lead to this massive performance penalty? Is this a known issue in Safari? I have only found this issue from another person with a similar project that ran into this problem ([link](https://bugs.webkit.org/show_bug.cgi?id=232662)).

Thanks for your time.

Sample time it takes to render a frame with a `-pthreads` build (time obtained via glfwGetTime(), it's in seconds):

```
RENDERING START 225.98
RENDERING END 265.033
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.