2

I have a tableview which download pictures of restaurants menu which range from 200 Kilobytes to 2 MB using kingFisher pod.

Downloaded Pictures

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "MealCell", for: indexPath) as! MealTableViewCell
    let defaultImage = UIImage(named: "DefaultMeal")
    cell.mealImageView.kf.setImage(with: url, placeholder: defaultImage, options: [.transition(.fade(0.3))])

    bla bla bla...

    return cell
}

I am not using prefetching , and I don't think if my problem is related to prefetching.

My main problem is when coming to a restaurant menu that is around 800 kb , the download process is start to be very slow.

enter image description here

And when scroll down very fast I have to wait around 1-2 minute for all my pics to download which comparing to my server upload speed and my home download speed is pretty far away.

I started searching everywhere for the same issue but I didn't find any.

I used this code increase downloader timeout and it worked for the images that stops downloading at all.

    KingfisherManager.shared.downloader.downloadTimeout = 600

And also when open network tab of Xcode debugger, I realize that my app is depending on just one TCP connection and as below picture, it only uses 73 KB/s for that big images.

Network Debugger

I Also tried this but the problem still where the Downloading is still depend in just one connection.

KingfisherManager.shared.downloader.sessionConfiguration.httpMaximumConnectionsPerHost = 8

What Exactly I am doing wrong, is there any way to download it faster.

Any help will be appreciated.

FamousMaxy
  • 686
  • 5
  • 21

1 Answers1

0

The image continues being downloaded after having scrolled past it. You want to cancel that request as the cell is no longer visible. I would recommend that you cancel the download in the cell's prepareForReuse method using cancelDownloadTask. Setting an image from one cell from showing up on another as cell are reused. Please let me know if this helps.

override func prepareForReuse() {
    super.prepareForReuse()

    icon.kf.cancelDownloadTask()
    icon.image = nil
}
user10447655
  • 180
  • 2
  • 10