Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace legacy image downloader with new actor-based implementation #4588

Merged
merged 4 commits into from Jan 24, 2024

Conversation

azarovalex
Copy link
Member

@azarovalex azarovalex commented Jan 23, 2024

The current image downloader is based on NSOperationQueue and has some bugs that I previously described in #4587. There is also a chance that these bugs caused memory corruption in some cases.

Instead of supporting sophisticated logic in legacy NSOperation-based implementation, I replaced it with new async/await implementation. It works the same way in fewer lines of code and because it's an actor, the compiler guarantees thread safety.

The only minor downside is that we can't use it on iOS 12, so I added another very simple implementation of the image downloader. It still caches responses but doesn't support reentrancy (meaning that 5 requests one after another will trigger 5 downloads), which is a trade-off we have to make.

TODO:

  • add changelog entry

@azarovalex azarovalex self-assigned this Jan 23, 2024
@azarovalex azarovalex requested a review from a team as a code owner January 23, 2024 17:29
Copy link

codecov bot commented Jan 23, 2024

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (ce064ed) 59.79% compared to head (2e0b7fd) 59.43%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #4588      +/-   ##
==========================================
- Coverage   59.79%   59.43%   -0.36%     
==========================================
  Files         189      189              
  Lines       21218    21037     -181     
==========================================
- Hits        12687    12504     -183     
- Misses       8531     8533       +2     
Files Coverage Δ
...oxNavigation/ImageDownloader/ImageDownloader.swift 100.00% <100.00%> (ø)
Sources/MapboxNavigation/SpriteRepository.swift 92.59% <100.00%> (-0.21%) ⬇️
...gation/ImageDownloader/LegacyImageDownloader.swift 92.85% <92.85%> (ø)
Sources/MapboxNavigation/ImageRepository.swift 81.81% <72.72%> (-3.29%) ⬇️

... and 1 file with indirect coverage changes

Copy link
Contributor

@Udumft Udumft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with few comments

Sources/MapboxNavigation/ImageRepository.swift Outdated Show resolved Hide resolved
@azarovalex azarovalex merged commit c976919 into main Jan 24, 2024
19 checks passed
@azarovalex azarovalex deleted the azarovalex/rewrite-image-downloader branch January 24, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants