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

Use WebAssembly to simulate universe state #43

Open
msakuta opened this issue Apr 3, 2022 · 0 comments
Open

Use WebAssembly to simulate universe state #43

msakuta opened this issue Apr 3, 2022 · 0 comments

Comments

@msakuta
Copy link
Owner

msakuta commented Apr 3, 2022

Using WebAssembly to simulate has two main benefits:

  • We can use exactly the same logic among the server and the browser
  • We can gain performance in CPU intensive simulation
  • The bundled Wasm file tend to be smaller than JS

The first point is important to keep the client synchronized with the server.
We can't always keep the server and the client synchronized, so the client needs to predict the simulation in its own.
Previously we did this by replicating the logic in TypeScript and Rust, but it is wasteful to implement it twice and it has better chance of bugs that logic may not work the same way.

For the second point, I measured the performance with the same condition.

Calculation with JavaScript (TypeScript):

image

Calculation with WebAssembly (Rust):

image

For WebAssembly, there is also another step to convert Wasm data to JavaScript (Three.js objects), but it seems that gain of performance by Wasm is greater than the overhead.

image

The drawback of wasm that I know of:

  • cargo deb doesn't work well with mixed targets in Rust workspace
  • Wasm's debug mode is very slow (much slower than TypeScript)

For the first point, the only solution right now is to delete orbiter-logic in root Cargo.toml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant