[Media] I Ported My Browser Game from TypeScript to Rust and Bevy - My Thoughts and Performance Comparison
![[Media] I Ported My Browser Game from TypeScript to Rust and Bevy - My Thoughts and Performance Comparison](https://i.redd.it/c5ekqktkhtbh1.jpeg)
How is it done?
I'm using Bevy on the client side, while the server is fully custom and written from scratch in Rust using Tokio, Axum, and SQLx.
Things like networking, area of interest, spatial queries, replication, and other systems were written by me. I'm using WebSockets as the transport layer. I previously used WebTransport, but some players had problems connecting, so I switched back to WebSockets.
The whole game was rewritten by hand, with some architectural improvements along the way. More recently, I started using AI-assisted coding, and honestly, it helps a lot, especially since I already know the entire codebase and can properly review the generated code. I've already added a few new features with AI assistance. Codex 5.4 Mini has been doing a good job for me so far.
Aside server and client I have custom editor to build maps, configure assets and add content (for example quests)
Bad things:
- WASM audio support has horrible performance. It causes heavy major GC spikes every few seconds, so I created a custom plugin that calls the JavaScript API directly.
- On some devices, there are issues with preloading assets or initializing them on the GPU. I'm still not sure what the actual cause is.
- In some cases, WebGL support is poor or problematic.
- Bevy UI is still at an early stage, and it can sometimes be problematic to work with.
- Game release build with all optimizations is taking around 10-15 minutes
- No official bevy editor (but not sure if I'd be using it anyway)
Good things:
- The raw WASM build is around 50 MB, but after Brotli compression (`.br`), it's only 22.6 MB for the whole game, including assets.
- Rigged animation performance is great. In the TypeScript version, I was using VAT animations, but at the moment I don't see much benefit from using them here.
- Asset management in bevy is really good
Performance difference:
The Bevy version has around 30–70% worse performance (from 4.0 ms frame to 7-8ms). It's hard to compare directly because it wasn't a 1:1 rewrite.
In some aspects, I see improvements, but in general, Bevy feels much more CPU-heavy than the TypeScript version. The TypeScript ↔ WASM overhead probably plays a part here as well.
Why rewrite?
In the previous version, the client and server were written in different languages: TypeScript and Java. I wanted to unify the codebase, but neither language was really what I wanted to use long-term. I had also always wanted to learn Rust, so rewriting the game felt like a good opportunity to do that.
Conclusion:
It was a little problematic, but it is definitely possible to create a playable WASM game with Rust and Bevy.
Game Link:
https://maiu-online.com/
Any questions?