bevyengine / bevyengine/bevy

Asset IDs Are Different for Same Path on Web and Desktop

Open
#6,275 7 comments 0 reactions 0 assignees View on GitHub
A-Assets C-Bug O-Web
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## Bevy version

v0.8.1

## What you did

Run this code, on web and desktop builds.

```rust
let path = "map/levels/lev01.map.json";
let asset_path: AssetPath = path.into();
let handle = Handle::::weak(asset_path.clone().into());
info!(?path, ?asset_path, ?handle, "Level 1 handle");
```

Observe the numbers for the handle in the logged output.

## What went wrong

**Expected:** The handle's generated on web to be the same as the handle generated on native.

**Actual result:** The handle IDs are different on web and desktop

## Additional information

I wanted to send the asset handles across the network for my networked game, but I'm going to have a Bevy server running on native, and clients running on web, so the difference in the handle ID is a blocker for that.

Having known that the Handle ID was a hash of the asset path, I was rather surprised to find that they were different on the different platforms.

I suspect that this has something to do with AHash using AES-NI instructions on native for extra prerformance, and then falling back to a different implementation on web, where those instructions don't exist.

## Is This a Bug?

I'd say it's debatable whether or not this is really a but and needs to be fixed. I would definitely like it fixed for my use-case, and I imagine other people would like to do the same thing, but I'd be good to collect thoughts from other users/developers.

## Solution

The only solution I think is to change the hash algorithm. Specifically mentioned in the AHash readme:

> Specifically, aHash is not intended for network use or in applications which persist hashed values. (In these cases `HighwayHash` would be a better choice)

It sounds like we should look into `HighwayHash`.

### Feature Flag

Since AHash's algorithm is specifically designed for speed only, it could have speed advantages over HighwayHash, so there might still be users who'd want to use it instead.

Maybe we could default to `HighwayHash` and provide a feature flag for using `AHash` instead?

I think we'd only want to do that, though, if we could find benchmarking or other evidence that shows `AHash` actually being faster in Bevy.

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.