Skip to content

Commit

Permalink
Remove SDWebImage dependency
Browse files Browse the repository at this point in the history
This proposes replaces usage of `SDWebImage` in the new `MemoryCache` following the comment #20956 (comment). It's only being used in one instance, to calculate the cost of objects added to the cache.

What's the difference between not passing in a cost and using `sd_memoryCost`? I'm not sure, so I'll share my current understanding and ask for feedback. For images, I don't see a difference because I think the cost is the image's size in bytes. For gifs (also `UIImage`s), the cost calculation seems more complex since I think it's only the number of frames loaded into memory (not the frames that are kept on disk).

This PR is meant to start a conversation about which option to take:
a. Let `NSCache` calculate the cost and remove `SDWebImage` from the Podfile
b. Re-implement a cost calculation and remove `SDWebImage` from the Podfile
c. Leave things as-is and close this PR

The assumption here is that by removing `SDWebImage`, we're not importing the library twice (once here and once in Gutenberg as a transitive dependency of a RN library).
  • Loading branch information
guarani authored and kean committed Nov 20, 2023
1 parent 701a249 commit 9b3b2df
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
1 change: 0 additions & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ abstract_target 'Apps' do
pod 'FSInteractiveMap', git: 'https://github.com/wordpress-mobile/FSInteractiveMap.git', tag: '0.2.0'
pod 'JTAppleCalendar', '~> 8.0.5'
pod 'CropViewController', '2.5.3'
pod 'SDWebImage', '~> 5.11.1'

## Automattic libraries
## ====================
Expand Down
8 changes: 1 addition & 7 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ PODS:
- OHHTTPStubs/Swift (9.1.0):
- OHHTTPStubs/Default
- Reachability (3.2)
- SDWebImage (5.11.1):
- SDWebImage/Core (= 5.11.1)
- SDWebImage/Core (5.11.1)
- Sentry (8.15.2):
- Sentry/Core (= 8.15.2)
- SentryPrivate (= 8.15.2)
Expand Down Expand Up @@ -120,7 +117,6 @@ DEPENDENCIES:
- OCMock (~> 3.4.3)
- OHHTTPStubs/Swift (~> 9.1.0)
- Reachability (= 3.2)
- SDWebImage (~> 5.11.1)
- Starscream (= 3.0.6)
- SVProgressHUD (= 2.2.5)
- SwiftLint (~> 0.50)
Expand Down Expand Up @@ -153,7 +149,6 @@ SPEC REPOS:
- OCMock
- OHHTTPStubs
- Reachability
- SDWebImage
- Sentry
- SentryPrivate
- Sodium
Expand Down Expand Up @@ -211,7 +206,6 @@ SPEC CHECKSUMS:
OCMock: 43565190abc78977ad44a61c0d20d7f0784d35ab
OHHTTPStubs: 90eac6d8f2c18317baeca36698523dc67c513831
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
Sentry: 6f5742b4c47c17c9adcf265f6f328cf4a0ed1923
SentryPrivate: b2f7996f37781080f04a946eb4e377ff63c64195
Sodium: 23d11554ecd556196d313cf6130d406dfe7ac6da
Expand All @@ -236,6 +230,6 @@ SPEC CHECKSUMS:
ZendeskSupportSDK: 3a8e508ab1d9dd22dc038df6c694466414e037ba
ZIPFoundation: d170fa8e270b2a32bef9dcdcabff5b8f1a5deced

PODFILE CHECKSUM: 8f21b7aab84e57d7e16119c89573229552c8c418
PODFILE CHECKSUM: beaa30560a95fe4f9e8153c20fa4b4ae54be1fd5

COCOAPODS: 1.14.2
3 changes: 1 addition & 2 deletions WordPress/Classes/ViewRelated/Media/MemoryCache.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation
import AlamofireImage
import WordPressUI
import SDWebImage

final class MemoryCache {
/// A shared image cache used by the entire system.
Expand All @@ -22,7 +21,7 @@ final class MemoryCache {
// MARK: - UIImage

func setImage(_ image: UIImage, forKey key: String) {
cache.setObject(image, forKey: key as NSString, cost: Int(image.sd_memoryCost))
cache.setObject(image, forKey: key as NSString)
}

func getImage(forKey key: String) -> UIImage? {
Expand Down

0 comments on commit 9b3b2df

Please sign in to comment.