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

Yaz compression horrendously slow #1

Closed
narahiero opened this issue Apr 3, 2020 · 3 comments
Closed

Yaz compression horrendously slow #1

narahiero opened this issue Apr 3, 2020 · 3 comments
Assignees
Labels
enhancement Improve an existing feature yaz module Any issue related to the Yaz module

Comments

@narahiero
Copy link
Owner

narahiero commented Apr 3, 2020

While testing SZS creation (U8 archive compressed with Yaz0), I was taken aback by how slow the compression was. I tested some other programs and they all took much less time to compress the same data.

Here is a table of the stats of some tools when compressing the same data (6,034 KB).

Tool name Time taken Compression quality
CTools (MrBean35000vr & Chadderz) < 1 sec 3,875 KB (36 %)
Wexos's Toolbox (Wexos) ~2 sec 3,463 KB (43 %)
Wiimms SZS Tools (Wiimms) ~3 sec 3,190 KB (47 %)
CT Lib 38 sec!!! 3,190 KB (47 %)

As you can see, Wiimms SZS Tools compresses as well as CT Lib, but is 10 times faster.

So the algorithm definitely needs some improvements. One enhancement I can think of right off the bat is to use raw pointers instead of a buffer, as it does bounds checking on every put/get operation.

@narahiero
Copy link
Owner Author

I just modified the compression code to only use raw pointers (to get rid of the Buffer class), but the compression time is unfortunately the exact same.

Looks like the problem is the algorithm itself... *sigh*

@narahiero
Copy link
Owner Author

Guess this issue will stay opened for a while. I can't think of a single way to improve the algorithm at the moment.

I might add some compression level in the near future as a temporary 'fix', but I know the algorithm can greatly be improved (Wiimms SZS Tools shows this).

@narahiero narahiero added the enhancement Improve an existing feature label Apr 4, 2020
@narahiero
Copy link
Owner Author

narahiero commented Apr 4, 2020

Alright! The commit I just made drastically improves performance, while retaining the same high compression quality.

Here is the updated tools' stats table as shown in the original post (6,034 KB).

Tool name Time taken Compression quality
CTools (MrBean35000vr & Chadderz) < 1 sec 3,875 KB (36 %)
Wexos's Toolbox (Wexos) ~2 sec 3,463 KB (43 %)
Wiimms SZS Tools (Wiimms) ~3 sec 3,190 KB (47 %)
CT Lib 6 sec 3,190 KB (47 %)

6 seconds! Yes! Thats 6 times faster than the old algorithm (38 seconds). Obviously, Wiimms SZS Tools is still the better one, but at least the speed of CT Lib is acceptable.

The only drawback of this new algorithm is that 4 MB of additional memory is allocated, which is used to make a table with the offsets to the occurrences of all possible byte values.

So, there's obviously still room for improvement, but I'd say it's good enough for now.

And I was saying that I had no idea on how to improve the algorithm 6 hours ago. LOL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improve an existing feature yaz module Any issue related to the Yaz module
Projects
None yet
Development

No branches or pull requests

1 participant