Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Massive save state speedup #37

Merged
merged 5 commits into from Nov 22, 2018
Merged

Massive save state speedup #37

merged 5 commits into from Nov 22, 2018

Conversation

Dr-Emann
Copy link
Contributor

Because libretro has an API that asks for the size seperately, and we
have to serialize to get the size, the end result is that we change from
2 serializations for each save state down to 1.

Because libretro has an API that asks for the size seperately, and we
have to serialize to get the size, the end result is that we change from
2 serializations for each save state down to 1.
Using serde_bytes to use bincode's fast path for bytes
By using the writer interface, there's no need to fully serialize into a
vec, then compress, we can do both at the same time
@Dr-Emann Dr-Emann changed the title Cache the last serialized state Massive save state speedup Nov 19, 2018
@Dr-Emann
Copy link
Contributor Author

I found a huge speedup: the overhead of serializing all the u8's individually in the the large Box<[u8]>s was huge. Serde has a solution to this: serializers have a serialize_bytes function (and bincode implements it very efficiently), however, until specialization lands, serde can't call it automatically. So just annotating the Box<[u8]> fields with #[serde(with = "serde_bytes")] causes the fields to be serialized with a single serialize_bytes call, instead of a ton of individual calls per u8.

On my system, this took the time to serialize from over 100ms to about 5ms.

Copy link
Member

@yupferris yupferris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! I like these changes :)

A couple things I'd like changed, but overall great work; once the nits have been addressed I'd love to go over this and merge it on the next stream :)

rustual-boy-libretro/src/lib.rs Outdated Show resolved Hide resolved
rustual-boy-serialization/src/version1.rs Outdated Show resolved Hide resolved
@Dr-Emann
Copy link
Contributor Author

I believe I've addressed the nits. It's pretty cool to be able to turn on rewind, and not bring things to a grinding halt.

@yupferris
Copy link
Member

Fantastic, thanks! I'll go over this and merge on the stream this evening. :)

@yupferris yupferris merged commit 0b6b679 into emu-rs:libretro Nov 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants