Optimize doResize method with binary search #6137
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This pull request addresses issues discussed in #6112 . Currently, if an uploaded image exceeds a certain size threshold, BlueSky reduces the image quality by 10% and checks if the new size falls within the threshold. If not, BlueSky repeats this step until the image quality reaches 0. There are two issues with this approach:
My proposed solution is to use binary search to find the maximum quality level that keeps the image size within the limit. This approach will prevent too much loss in image quality. Not only that, I also ran some benchmarks, and it appears that the current solution may perform slightly better for smaller images. However, for larger images, the binary search method does much better. That said, I only conducted a few tests here, so additional testing may be needed to confirm the difference.