Luban icon indicating copy to clipboard operation
Luban copied to clipboard

压缩速度下降&内存占用增多的性能问题

Open danielchow opened this issue 5 years ago • 2 comments

这次提交引起了压缩速度&内存占用的性能下降问题:https://github.com/Curzibn/Luban/commit/4701a87cfb6f4a5402ba48965c694f7296b83c46

具体如下:

  1. Checker.isJPG()从判断文件后缀,改为判断文件头部特征字节;
  2. 旋转图片去除了ExifInterface依赖,改为判断文件头;
  3. Engine.java中,有Checker.SINGLE.isJPG(srcImg.open())Checker.SINGLE.getOrientation(srcImg.open())两处,这两处代码都将整个原始图片文件读入了内存当中;

综上,会有两次比较慢的完整读取原始文件的操作,原始文件较大时可能OOM。 Checker.isJPG()可以只读入前几个字节,请问去除ExifInterface依赖的主要原因是什么呢?

danielchow avatar Jul 20 '18 09:07 danielchow

去除ExifInterface依赖是想避免部分开发者未正确添加依赖而报错。如果您有好的思路还请不吝赐教。如果能提交PR更好

Curzibn avatar Aug 16 '18 06:08 Curzibn

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 4186124 byte allocation with 3501024 free bytes and 3MB until OOM at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91) at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201) at top.zibin.luban.Checker.toByteArray(Checker.java:204) at top.zibin.luban.Checker.isJPG(Checker.java:44) at top.zibin.luban.Engine.compress(Engine.java:76) at top.zibin.luban.Luban.compress(Luban.java:180) at top.zibin.luban.Luban.access$700(Luban.java:21) at top.zibin.luban.Luban$1.run(Luban.java:135) at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1115) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:590) at java.lang.Thread.run(Thread.java:818)

leon2017 avatar Jan 30 '19 10:01 leon2017