SDWebImage / SDWebImageLinkPlugin

A SDWebImage loader plugin, to support load rich link image with LinkPresentation framework
MIT License
17 stars 2 forks source link

Fastest way to use in large UICollectionView #17

Open inPhilly opened 4 years ago

inPhilly commented 4 years ago

You've done a great job on the plugin. I'm revisiting after being away for a while. It wasn't exactly clear from your ReadMe - which method you described would be the fastest way to load a large UICollectionView of links from scratch (i.e. nothing in cache). Would you use the imageView, or the LPLinkView, or would you save the metadata? In any of these methods, will a large collectionView actually load quickly? No matter what I do so far, if I scroll a collectionView with many objects quickly on an iPad using any of these methods, the app seems to freeze up rather quickly. I would love to hear if you have any further insight into the matter -- and especially if you have an example! (that doesn't use CocoaPods)

dreampiggy commented 4 years ago

Use LPLinkView with the already cached (already queried and using NSCoding to read from disk or memory)LPLinkMetada, fastest.

dreampiggy commented 4 years ago

We have example use CocoaPods, I don't know why you say "Don't use CocoaPods", it just a ruby tool and does not force you to use (Use CocoaPods in our Example != Use CocoaPods for your project).

If you do not use CocoaPods, just copy all the source code in demo and use any of your own dependency manager instead.

inPhilly commented 4 years ago

I was just wondering if you had an example of a UICollectionView with a lot of URLS that doesn't freeze up when scrolled quickly. When I use LPLinkView with LPLinkMetadata (I don't deal directly with the metadata), the UICollectionView freezes up when scrolled. I am testing on an iPad and can show about 12 cells at once, and have over 100 total.

inPhilly commented 4 years ago

You are saying to do this, right?

Load Rich Link on LPLinkView

Important note on LPLinkView: Current iOS 13.0 contains bug that LPLinkView may not compatible with TableView/CollectionView cell-reusing. To workaround this issue, you can choose one of these below (one is OK):

Do not using cache at all. So, always pass SDWebImageFromLoaderOnly to load the metadata from network Using trick code, create LPLinkView with empty LPLinkMetadata, or nil URL (important).

Objective-C
NSURL *url = [NSURL URLWithString:@"https://www.apple.com/iphone/"];
self.linkView = [[LPLinkView alloc] initWithURL:nil];
[self.view addSubview:self.linkView];
[self.linkView sd_setImageWithURL:url completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
    if (image && [image.sd_extendedObject isKindOfClass:LPLinkMetadata.class]) {
        NSLog(@"%@", @"LPLinkView metadata load success");
    }
}];

How would you set up the loader for this? Would you use a custom loader? Would you use a loader with no caching?

I'm sorry, I just can't seem to get this to work well and I am trying to figure out if there is even a chance to have a decent loading experience for many urls scrolled on a UICollectionView.

dreampiggy commented 4 years ago
  1. I was just wondering if you had an example of a UICollectionView with a lot of URLS that doesn't freeze up when scrolled quickly

If you think there are performance issue, you can write a demo to test. Our demo here use UITableView currently...And it's not hard to do so. I'm busying contribution on the [Firebase-UI])(https://github.com/firebase/FirebaseUI-iOS/tree/master/Storage) at the time I write this comment, so maybe I have no time to do so..

  1. When I use LPLinkView with LPLinkMetadata (I don't deal directly with the metadata), the UICollectionView freezes up when scrolled

If you find something about the FPS issue or performance issue, you should use Instruments to profile, which is the best and correct way to do, not just guess and check. If you don't know how to use Instruments, check all the resources from online or Apple, like:

inPhilly commented 4 years ago

Okay. Your tableview example is pretty slow to load and tends to freeze up as well. I was just wondering if you had any better examples since then. I don't think this is a matter for instruments - I think this is just that LinkPresentation framework was not made for volume use, especially since it blocks the main thread when LPLinkMetadata is fetched.

dreampiggy commented 4 years ago

I think this is just that LinkPresentation framework was not made for volume use, especially since it blocks the main thread when LPLinkMetadata is fetched.

You still say "I think", but not "I found". You should provide the evidence. If they block main queue, attach the Instrument Time Profile result (When you run your App or Example, you can save the result to disk), which show the main queue method trace and timing, if they block main queue, it's Apple's WebKit team's fault and they need to fix, fire the Radar and your Instruments result to https://feedbackassistant.apple.com/