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

Remove SDWebImage dependency #21285

Merged
merged 3 commits into from
Nov 20, 2023
Merged

Remove SDWebImage dependency #21285

merged 3 commits into from
Nov 20, 2023

Conversation

guarani
Copy link
Contributor

@guarani guarani commented Aug 8, 2023

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 UIImages), 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).

To test: TO-DO

Regression Notes

  1. Potential unintended areas of impact: TO-DO
  2. What I did to test those areas of impact (or what existing automated tests I relied on): TO-DO
  3. What automated tests I added (or what prevented me from doing so): TO-DO

PR submission checklist:

  • I have completed the Regression Notes.
  • I have considered adding unit tests for my changes.
  • I have considered adding accessibility improvements for my changes.
  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

UI Changes testing checklist:

  • Portrait and landscape orientations.
  • Light and dark modes.
  • Fonts: Larger, smaller and bold text.
  • High contrast.
  • VoiceOver.
  • Languages with large words or with letters/accents not frequently used in English.
  • Right-to-left languages. (Even if translation isn’t complete, formatting should still respect the right-to-left layout)
  • iPhone and iPad.
  • Multi-tasking: Split view and Slide over. (iPad)

@guarani guarani requested a review from kean August 8, 2023 16:24
@guarani
Copy link
Contributor Author

guarani commented Aug 8, 2023

👋 @kean, would you be able to give me your thoughts on this as a follow-up to #20956 (comment)? The main thing I'm not sure about is what the value of the cache cost calculation that SDWebImage provides is.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Aug 8, 2023

WordPress Alpha📲 You can test the changes from this Pull Request in WordPress Alpha by scanning the QR code below to install the corresponding build.
App NameWordPress Alpha WordPress Alpha
ConfigurationRelease-Alpha
Build Numberpr21285-9d83e7f
Version23.7
Bundle IDorg.wordpress.alpha
Commit9d83e7f
App Center BuildWPiOS - One-Offs #7888
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@wpmobilebot
Copy link
Contributor

wpmobilebot commented Aug 8, 2023

Jetpack Alpha📲 You can test the changes from this Pull Request in Jetpack Alpha by scanning the QR code below to install the corresponding build.
App NameJetpack Alpha Jetpack Alpha
ConfigurationRelease-Alpha
Build Numberpr21285-9d83e7f
Version23.7
Bundle IDcom.jetpack.alpha
Commit9d83e7f
App Center Buildjetpack-installable-builds #6912
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@kean
Copy link
Contributor

kean commented Aug 8, 2023

@guarani I'd suggest going with option B and reimplementing the SDWebImage version: UIImage+MemoryCacheCost.m.

What's the difference between not passing in a cost and using sd_memoryCost?

If you don't pass the cost, it'll be 0 (only documented in the headers):

- (void)setObject:(ObjectType)obj forKey:(KeyType)key; // 0 cost

The cost must be non-zero in order for the totalCostLimit to work.

For gifs (also UIImages), 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).

SDWebImage also handles it, but we are not using images for rendering. The app caches original image data (Data). Gifu creates CGImage instances manually for each frame. These are not stored in our caches.

guarani and others added 2 commits November 20, 2023 14:12
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).
@kean kean marked this pull request as ready for review November 20, 2023 19:28
@kean
Copy link
Contributor

kean commented Nov 20, 2023

I rebased it and updated cost calculation – ready for merge.

@kean kean enabled auto-merge November 20, 2023 19:28
@wpmobilebot
Copy link
Contributor

1 Warning
⚠️ PR is not assigned to a milestone.

Generated by 🚫 Danger

@kean kean added this to the 23.8 milestone Nov 20, 2023
@kean kean merged commit c0af91d into trunk Nov 20, 2023
22 of 23 checks passed
@kean kean deleted the task/remove_sdwebimage branch November 20, 2023 22:18
@guarani
Copy link
Contributor Author

guarani commented Nov 22, 2023

Thanks @kean!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants