Very dangerous and unoptimized code inside library!
See original GitHub issueprivate static Bitmap getImageResized(Context context, Uri selectedImage) {
int[] sampleSizes = new int[]{5, 3, 2, 1};
int i = 0;
Bitmap bm;
do {
bm = decodeBitmap(context, selectedImage, sampleSizes[i]);
++i;
} while(bm != null && (bm.getWidth() < minWidthQuality || bm.getHeight() < minHeightQuality) && i < sampleSizes.length);
Log.i(TAG, "Final bitmap width = " + (bm != null?Integer.valueOf(bm.getWidth()):"No final bitmap"));
return bm;
}
This code is absolutely HORRIBLE for these 3 reasons:
- Wastes CPU resources by creating up to 4 different bitmaps unnecessarily.
- Risks OutOfMemory crash by potentially loading a too-large Bitmap into RAM (you don’t check the size from file before loading Bitmap, it might be 100 megapixels as far as I’m concerned)
- Creates huge memory churn (again, by creating 4 unnecessary Bitmaps) which are then unnecessarily left for Garbage Collector to handle…
Please watch this video to learn how to load images properly from files: https://www.youtube.com/watch?v=HY9aaXHx8yA
I won’t use your library for these reasons.
Issue Analytics
- State:
- Created 6 years ago
- Comments:11 (8 by maintainers)
Top Results From Across the Web
Is optimization dangerous? [closed] - Stack Overflow
Optimising code takes time from the developers that they could instead use to add new features or polish their product.
Read more >Build optimizer breaks third party libraries #12128 - GitHub
Scaffold a project that uses code (e.g. a third party library) that contains code that cannot be properly "optimized" using uglifyjs.
Read more >Dangerous Optimizations and the Loss of Causality
THIS MATERIAL OF CARNEGIE MELLON UNIVERSITY AND ITS SOFTWARE ENGINEERING. INSTITUTE IS FURNISHED ON AN “AS-IS" BASIS.
Read more >Optimizing an Elm Library - crowdstrike.com
The library I optimized is one we use to calculate the Levenshtein edit distance between two strings. The final tally of speedups are ......
Read more >Is it bad practice to write code that relies on compiler ...
In the particular case of C++'s (N)RVO, yes, relying on this optimisation is perfectly valid. This is because the C++17 standard specifically ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I was just saying that you are free to give a better solution if you think there is a better way to do it. I will take it into account and will try to improve it in the next days/weeks.
Thank you for your comment and your help. And sorry if I was too rude, it wasn’t my intention.
@gajicm93 not sure if it will get merged but you can use my branch to get around the issue if you need to.