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

Asynchronous decompression of compressed formats #4319

Closed
Anuskuss opened this issue Mar 24, 2021 · 5 comments · Fixed by #4321
Closed

Asynchronous decompression of compressed formats #4319

Anuskuss opened this issue Mar 24, 2021 · 5 comments · Fixed by #4321

Comments

@Anuskuss
Copy link

Anuskuss commented Mar 24, 2021

Now that PCSX2 is getting more and more accurate with disc timings and compressed formats like CSO and CHD getting increasingly popular, it would be unwise not to (further) improve the decompression performance to avoid any stutters/glitches.

We currently support using the OS's async IO for reading isos, but don't have anything in place for decompressing on a separate thread

@TellowKrinkle TellowKrinkle self-assigned this Mar 24, 2021
@TellowKrinkle TellowKrinkle changed the title [Feature Request] Improve performance of compressed formats Asynchronous decompression of compressed formats Mar 24, 2021
@rtissera
Copy link
Contributor

Regarding CHD I am considering implementing in https://github.com/rtissera/libchdr read-ahead decompression in a separate thread which could be enabled or not a compile-time, in order to minimize any stutter / latency.

@avih
Copy link
Contributor

avih commented Mar 24, 2021

read-ahead decompression

This might work well, or might make things worse, depending on the disc access pattern of the game.

For instance, Shadow of the Colossus (I don't recall if the EU or US version) reads just all over the place, and constantly seem to be seeking to random locations at the DVD (I analyzed many games when I added the gzip support). At such case, readahead is very likely to make things worse.

Also, consider that seeks are very slow with physical DVD, and games know this and access the disk accordingly. I think the async file reader API can already do exactly what the game expects, so as long as you implement the async API actually async, I think you should be good.

@TellowKrinkle
Copy link
Member

TellowKrinkle commented Mar 25, 2021

Also, consider that seeks are very slow with physical DVD, and games know this and access the disk accordingly. I think the async file reader API can already do exactly what the game expects, so as long as you implement the async API actually async, I think you should be good.

It looks like we're having no trouble keeping up with large seeks, but end up negative on smaller seeks (ReadAsync blocks are the time it took the EE thread gave between requesting a read and requesting its completion, the little marks above are points where the decompression thread finished a read (so if it's inside of the block, it finished in time, otherwise it made the EE thread wait), I marked the blocks with the size of the seek they were doing)
image
(This is with 1MB LZMA blocks)

Edit: Forgot to turn the frame limiter back on. Not going to relabel but here's the same spot with the frame limiter on, we make a lot more of the reads in time now
image

@avih
Copy link
Contributor

avih commented Mar 25, 2021

we make a lot more of the reads in time now

For the game which you tested.

As I mentioned, disk access pattern changes a LOT between games, and the only way to assess the change in general is to repeat this test with a LOT of games, and examine the overall results.

@TellowKrinkle
Copy link
Member

For the game which you tested.

If we finish the read + readahead it in the amount of time PCSX2 gives for an emulated seek (we don't in the above case but probably would with ~half the block size), I don't see how a game's seek pattern could break it

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

Successfully merging a pull request may close this issue.

4 participants