mirror of
https://github.com/libretro/RetroArch.git
synced 2026-11-07 08:36:02 -10:00
A replay records or plays back a checkpoint every few seconds, in the middle of the game, and each took fresh state-sized buffers: the statestream encoding (half again the state), the compressed copy - calloc'd, zeroed only to be overwritten by the compressor - and on playback the compressed copy read from the file and a calloc'd buffer to decode into, then copied into cur_save for a raw state. The handle now keeps the encoding and compression buffers (bsv_movie_scratch()), grown only when a state outgrows them, never zeroed, freed with the movie. A raw state is inflated straight into cur_save, so its copy is gone too. A zlib checkpoint whose buffer could not be taken now fails instead of compressing into NULL, and a checkpoint that fails part way marks cur_save as holding no state. The buffers a zstd checkpoint of a raw state takes and touches, per checkpoint (the codec's own work aside): 4 MiB 0.81 -> 0.41 ms, 16 MiB 2.66 -> 1.35 ms, 64 MiB 45.5 -> 9.0 ms. bsv_statestream_test gains a lane that records and plays back eight checkpoints, raw and statestream, plain and zstd, each decoding to the bytes written, with nothing state-sized of the replay's own allocated after the first two (what zstd allocates inside a call is measured through rzstd directly and allowed for). It fails on the previous bsvmovie.c. bsv_checkpoint_bounds_test's copy of bsv_movie_load_checkpoint() follows the shipping one again, with bsv_movie_set_end() and the size checks it had fallen behind on.