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

WASM unusably slow even for a trivial example in Brave Browser #7242

Open
smessmer opened this issue Jan 16, 2023 · 13 comments
Open

WASM unusably slow even for a trivial example in Brave Browser #7242

smessmer opened this issue Jan 16, 2023 · 13 comments
Labels
C-Performance A change motivated by improving speed, memory usage or compile times O-Web Specific to web (WASM) builds

Comments

@smessmer
Copy link
Contributor

I've created a very simple example that just adds a 2d camera and shows an fps counter. Running it as a desktop app is fine and shows 60 FPS. But when trying to run it in a browser with WASM (using wasm-server-runner), it hovers around 30 FPS for a couple seconds and then drops down to 5 FPS where it stays.

Why is this so slow? This is a trivial example that isn't really doing anything except for showing the FPS counter. Anything I can do to make it faster?

Code: https://github.com/smessmer/bevy-wasm-test

Run with:

cargo install wasm-server-runner
cargo run --release --target wasm32-unknown-unknown
@smessmer smessmer added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 16, 2023
@mockersf
Copy link
Member

This is due to how browser handles activity and the interaction with desktop mode.

Browsers are very aggressive to trigger inactivity, and your wasm app will run at the slowest rate almost as soon as you don't move the mouse cursor

@mockersf mockersf added O-Web Specific to web (WASM) builds and removed C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Jan 16, 2023
@smessmer
Copy link
Contributor Author

smessmer commented Jan 16, 2023

Constantly moving the mouse cursor or pressing keys doesn't change anything. I also have the same effect with a more complex game where pressing keys can move a player character around. It very quickly drops down to an unusable number of FPS even when constantly moving the player character around.

How is this supposed to be used? Anything I can change in my project setup or code to make it usable?

@mockersf
Copy link
Member

How are you building? Is https://bevyengine.org/examples/games/breakout/ slow too?

@smessmer
Copy link
Contributor Author

Oh it seems to be browser specific. I was using the Brave browser and both my example and the online Breakout example are unusably slow. With Chrome, both run better. Not sure why Brave slows it down so much.

@alice-i-cecile alice-i-cecile added the C-Bug An unexpected or incorrect behavior label Jan 16, 2023
@alice-i-cecile
Copy link
Member

Super useful: can you note that this is Brave specific in the issue title?

@alice-i-cecile alice-i-cecile added C-Performance A change motivated by improving speed, memory usage or compile times and removed C-Bug An unexpected or incorrect behavior labels Jan 16, 2023
@smessmer smessmer changed the title WASM unusably slow even for a trivial example [Brave Browser] WASM unusably slow even for a trivial example Jan 16, 2023
@smessmer smessmer changed the title [Brave Browser] WASM unusably slow even for a trivial example WASM unusably slow even for a trivial example in Brave Browser Jan 16, 2023
@LoopyAshy
Copy link
Contributor

I presume you are using hardware acceleration in your browser?

@smessmer
Copy link
Contributor Author

The "Use hardware acceleration when available" setting is enabled

@smessmer
Copy link
Contributor Author

smessmer commented Jan 17, 2023 via email

@LoopyAshy
Copy link
Contributor

LoopyAshy commented Jan 17, 2023

On my device which is:
CPU: Intel i9 13900k
GPU: Nvidia RTX 3090 TI
OS: Windows 11
The example breakout runs perfectly at a stable max fps on Brave and Chrome with hardware acceleration on(with hardware acceleration off it is however much slower and runs much more poorly), however I do notice that for whatever reason I do not get audio on brave or chrome in my tests.
I do notice however that it runs better on Firefox in terms of having audio and Firefox along with Chrome also oddly have much less CPU usage (starts at up to 20% CPU usage when I load the game but eventually drops to 1-7, while Firefox and Chrome starts and stays at a stable 0.5-1.5) but I am not convinced that it is the game causing that as I get a similar huge increase in CPU usage when I load the bevy site in general via Brave and over several minutes it drops to a stable value however it lingers even when the tab is closed and I am not sure why this is as this never occurs in any other browser I have tried so it must be specific to Brave? (potentially ad blocker or similar getting confused?).
Please note I do not have any extensions in any of the tested browsers other than what comes by default if any.

Within my tests however I did note a issue in the example when running it in all 3 browsers where resizing the windows horizontally would cause it to infinitely grow.

This has been made into its own issue at: #7250 (Was a duplicate of bevyengine/bevy-website#432)

However I will attempt to compile breakout myself in near future if required to thoroughly test it for potential performance drops in specific browsers.

@smessmer
Copy link
Contributor Author

smessmer commented Jan 18, 2023

For me, breakout is slow even on the public website, no need to compile it myself.
I now also tried it on Ubuntu 22.04, same issue for me. The breakout example at https://bevyengine.org/examples/games/breakout/ has about 5-10 fps only.

CPU: Intel(R) Core(TM) i9-7980XE CPU @ 2.60GHz
Graphics: Nvidia GeForce RTX 2080 Ti Rev. A

I have the "hardware acceleration" setting enabled in Brave, but not sure if that means it uses the Nvidia card or whether it might be using the graphics card included in the CPU. I did just notice that webglreport.com in Brave says:

Unmasked Vendor: | Google Inc. (Google)
ANGLE (Google, Vulkan 1.3.0 (SwiftShader Device (Subzero) (0x0000C0DE)), SwiftShader driver)

while Chrome says:

Unmasked Vendor: | Google Inc. (NVIDIA)
ANGLE (NVIDIA, Vulkan 1.2.175 (NVIDIA NVIDIA GeForce RTX 2080 Ti (0x00001E07)), NVIDIA)

But I would assume the breakout example (and even more so the example I coded which doesn't actually display anything except for an fps counter) is simple enough that even the CPU internal graphics should be able to handle it well?

@mockersf
Copy link
Member

Bevy examples will also report in the browser console which gpu it's using

@smessmer
Copy link
Contributor Author

Browser console reports the same thing I saw in webglreport.com

@fredo838
Copy link

For me, using Google Chrome, the breakout example runs at 3 fps, on a Thinkpad X1 carbon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Performance A change motivated by improving speed, memory usage or compile times O-Web Specific to web (WASM) builds
Projects
None yet
Development

No branches or pull requests

5 participants