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

Slow path detected when compressing a big file #35

Open
raysan5 opened this issue Jan 28, 2022 · 2 comments
Open

Slow path detected when compressing a big file #35

raysan5 opened this issue Jan 28, 2022 · 2 comments

Comments

@raysan5
Copy link

raysan5 commented Jan 28, 2022

Hi! When trying to compress a 4096x4096 RGBA (32bit per pixel) image I noticed it was quite slow (about 14 seconds on my old [email protected], 8GB RAM), compiled in release mode, optimized for fast.

Analysing the process with Visual Studio 2022 it seems to find a Hot Path in sdefl_fnd() and sdefl_uload32(), is it expected? Do you know if there could be any issue in that point?

rpng_save_image_sdefl_fnd_slow_path

I tested saving the same image data with stbi_write_png() and it takes about 4 seconds.

For comparison I also tested it with the QOI file format and it takes less than a second.

About the output compressed sizes (it could be related), I got:

 - rpng (sdefl) -> 5012KB
 - stbi ---------> 7392KB
 - qoi ----------> 8792KB

Maybe the issue is on my side when providing the scanlines for compression? The compression size is quite small, it makes sense it could take way longer to process...

Please, note that this is more an issue for discussion than an actual problem, it just call my attention and I decided to ask.

@vurtun
Copy link
Owner

vurtun commented Jan 30, 2022

Hey Ray,
the hot path here is the LZ-matcher (basically a list of possible past occurrences of string). Looks like this particular file has a lot of repetitive matches for a specific string. So the matcher walks through them and checks a lot of them to find the best one (as in longest match) in the current window.

What compression level did you pick? I have an upper bound for number of matches checked and for lower levels a best match that will stop checking additional matches if currently checked match is long enough already.

BTW to check that thesis it may be interesting to trace how many matches are checked for that particular file.

@raysan5
Copy link
Author

raysan5 commented Jan 30, 2022

Hi Micha, thanks for the answer!

I'm using the compression level 8, I think it's the same used by stbwi. I checked the code and it defines a max_chain = 8192, I'll try to do some tests with it...

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

No branches or pull requests

2 participants