Consider making serialization deterministic
- Vorherrschende Sprache
- Rust
- Sterne
- 41
- Forks
- 2
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
This doesn't affect functionality in any real way, but currently serialization is non-deterministic, meaning serializing, deserializing, and then serializing the world again doesn't always result in the same serialization the second time.
MRE to demonstrate: (May need to run a few times to get a fail, sometimes you'll get lucky)
```rust
pub type TestWorldRegistry = Registry!(f32, i32);
#[test]
pub fn test_serialize_world() {
let mut world = World::::new();
world.insert(entity!(16f32));
world.insert(entity!(32i32));
let serialized_a = bincode::serialize(&world).unwrap();
let deserialized_world: World = bincode::deserialize(&serialized_a).unwrap();
let serialized_b = bincode::serialize(&deserialized_world).unwrap();
assert_eq!(serialized_a, serialized_b);
}
```
Possible fix that appears to work, in `archetypes/impl_serde.rs` @ line 30
```rust
fn serialize(&self, serializer: S) -> Result
where
S: Serializer,
{
let mut archetypes: Vec<_> = self.iter().collect();
archetypes.sort_by(|a, b| unsafe {
let ident1 = a.identifier();
let ident2 = b.identifier();
ident1.iter().cmp(ident2.iter())
});
serializer.collect_seq(archetypes)
}
```
Of course, this does have a performance impact, but given it's unlikely for the number of archetypes to ever approach the number of entities in a scene, I believe it's negligible.
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Bewertung
Dieses Issue wurde noch nicht bewertet.