{"action":"created","issue":{"url":"https://api.github.com/repos/bumptech/glide/issues/731","labels_url":"https://api.github.com/repos/bumptech/glide/issues/731/labels{/name}","comments_url":"https://api.github.com/repos/bumptech/glide/issues/731/comments","events_url":"https://api.github.com/repos/bumptech/glide/issues/731/events","html_url":"https://github.com/bumptech/glide/issues/731","id":115744073,"number":731,"title":"Why loading a small image with Glide costs more time than loading it directly?","user":{"login":"licheedev","id":10960780,"avatar_url":"https://avatars.githubusercontent.com/u/10960780?v=3","gravatar_id":"","url":"https://api.github.com/users/licheedev","html_url":"https://github.com/licheedev","followers_url":"https://api.github.com/users/licheedev/followers","following_url":"https://api.github.com/users/licheedev/following{/other_user}","gists_url":"https://api.github.com/users/licheedev/gists{/gist_id}","starred_url":"https://api.github.com/users/licheedev/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/licheedev/subscriptions","organizations_url":"https://api.github.com/users/licheedev/orgs","repos_url":"https://api.github.com/users/licheedev/repos","events_url":"https://api.github.com/users/licheedev/events{/privacy}","received_events_url":"https://api.github.com/users/licheedev/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/bumptech/glide/labels/question","name":"question","color":"d4c5f9"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-08T16:53:41Z","updated_at":"2015-11-08T17:56:44Z","closed_at":null,"body":"First. Let's watch this gif.\r\n![img1](https://raw.githubusercontent.com/licheedev/filestore/master/img/glide/1.gif)\r\nWorks well.\r\n\r\nBut watch another one. \r\n![img2](https://raw.githubusercontent.com/licheedev/filestore/master/img/glide/2.gif)\r\n\r\nForce stop the application and lanuch it again. \r\nIt is obvious that loding image with Glide is `slower (several milliseconds)` than loading it with ImageView directly.\r\n\r\nAnd lastly, the 3rd one.Let's make a comparison.\r\n![img3](https://raw.githubusercontent.com/licheedev/filestore/master/img/glide/3.gif)\r\n\r\nThe size of sample image [doge.jpg](https://raw.githubusercontent.com/licheedev/Glide-Issue/master/app/src/main/res/drawable/doge.jpg) is just 484*252. I don't konw why Glide loads it so slowly.\r\n\r\n```java\r\n    public void load(View view) {\r\n        Glide.with(this)\r\n            .load(R.drawable.doge)\r\n            .fitCenter()\r\n            .diskCacheStrategy(DiskCacheStrategy.ALL)\r\n            .dontAnimate()\r\n            .into(mIvGlide);\r\n\r\n        mIvOrigin.setImageResource(R.drawable.doge);\r\n    }\r\n```\r\n\r\nI even make Glide cache all. \r\nBut no matter how small the image is, Glide always costs `SOME TIME` to lode it.\r\n`NOTINGH FOR A WHILE, THAN THE IMAGE`. \r\nLooks elegant. \r\n\r\nThe demo is here https://github.com/licheedev/Glide-Issue . NEED HELP.\r\n\r\n\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/bumptech/glide/issues/comments/154853084","html_url":"https://github.com/bumptech/glide/issues/731#issuecomment-154853084","issue_url":"https://api.github.com/repos/bumptech/glide/issues/731","id":154853084,"user":{"login":"TWiStErRob","id":2906988,"avatar_url":"https://avatars.githubusercontent.com/u/2906988?v=3","gravatar_id":"","url":"https://api.github.com/users/TWiStErRob","html_url":"https://github.com/TWiStErRob","followers_url":"https://api.github.com/users/TWiStErRob/followers","following_url":"https://api.github.com/users/TWiStErRob/following{/other_user}","gists_url":"https://api.github.com/users/TWiStErRob/gists{/gist_id}","starred_url":"https://api.github.com/users/TWiStErRob/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TWiStErRob/subscriptions","organizations_url":"https://api.github.com/users/TWiStErRob/orgs","repos_url":"https://api.github.com/users/TWiStErRob/repos","events_url":"https://api.github.com/users/TWiStErRob/events{/privacy}","received_events_url":"https://api.github.com/users/TWiStErRob/received_events","type":"User","site_admin":false},"created_at":"2015-11-08T17:56:44Z","updated_at":"2015-11-08T17:56:44Z","body":"Without trying your demo I have a strong hunch. I think you should be loading images through File objects or paths for this kind of test. Reading my best guess below should show you why. It is actually the simplest explanation - with a lot of detail. I may be wrong but it's worth considering the points below.\r\n\r\nLoading resources in Android happens on the UI thread. So even though your `setImageResource` is after the Glide load it will happen before Glide has a chance of doing anything at all. Here's how I imageine this goes down:\r\n * Glide posts load to background thread for `mIvGlide`.\r\n * `setImageResource` sets image on `mIvOrigin` causing layout.\r\n * Meanwhile Glide has figured out it's dealing with a resource and loads it in the background.\r\n * At this time the UI thread already had time to draw the first image,  \r\neven if it didn't it's in the main loop's queue.\r\n * Glide is finished transcoding and everything so it calls `Target.setResource` on the UI thread,  \r\nwhich also uses the main loop's queue.\r\n * `DrawableImageViewTarget` calls `setImageDrawable` and causes a layout.\r\n * Image loaded by Glide is drawn after layout.\r\n\r\nSo we have 4 UI loops:\r\n * original `load(View view)` call, setting `mIvOrigin`, causing layout\r\n * Scheduled layout for `mIvOrigin` executes\r\n * Glide's posted `Target.setResource` setting `mIvGlide`, causing layout\r\n * Scheduled layout for `mIvGlide` executes\r\n\r\nNotice how loading the resource via `setImageResource` actually blocks Glide, even if Glide finished loading the image first on the background thread. Glide simply posting the resulting resource back to the UI thread puts in into the Main loop and it has to wait for the load, layout and draw of the direct-loaded image.\r\n\r\nTop this by adding `diskCacheStrategy(ALL)` which results in copying the drawable stream from the APK to the disk cache on internal storage (usually the same device) and then decoding it from the freshly copied image. This means that decoding is, again, blocked by something unnecessary. If you ran it at least once before, the `RESULT` cache should help it a lot by loading a perfectly sized image for the ImageView. This is usually smaller than original, but in your case it may be upscaled depending on how you set up the Genymotion device's DPI. Let's assume it's smaller, even then we have to go back to the previous reasoning to see how that possibly faster loading is blocked by loading the original drawable sync.\r\n\r\nAlso your first gif works well because the image is loaded from memory cache. In that version of things the two layouts actually happen together, because hitting memory cache within Glide is sync, so in that case `mIvGlide.setImageDrawable` is actually called before `mIvOrigin.setImageResource` in the same UI loop."}}