GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Deprecate dispatch_main_async_safe, introduce two more policy `.safeAsyncMainThread` (for UIKit diffable data source) and `.safeAsyncMainQueue` (for most common cases) by dreampiggy · Pull Request #3766 · SDWebImage/SDWebImage

Conversation

@dreampiggy

@dreampiggy dreampiggy commented Nov 8, 2024

Copy link
Copy Markdown
Contributor

New Pull Request Checklist

  • I have read and understood the CONTRIBUTING guide

  • I have read the Documentation

  • I have searched for a similar pull request in the project and found none

  • I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)

  • I have added the required tests to prove the fix/feature I am adding

  • I have updated the documentation (if necessary)

  • I have run the tests and they pass

  • I have run the lint and it passes (pod lib lint)

This merge request fixes / refers to the following issues: ...

Pull Request Description

This close #3765

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@dreampiggy
Deprecate dispatch_main_async_safe, UIView+WebCache API now supports …
b4eeb0f
…SDCallbackQueue and may callback in non-main queue
@dreampiggy dreampiggy mentioned this pull request Nov 8, 2024
dispatch_main_async_safe issue #3765
Closed
@dreampiggy
dreampiggy force-pushed the bugfix/uiview_webcache_sdcallbackqueue branch from f9f14cf to 9db39a4 Compare November 11, 2024 09:23
@dreampiggy
Added SDCallbackPolicyMainAsyncSafe which has better compatibility …
ed1f0f8
…for UI-related code logic

Handled two cases in real-world app
@dreampiggy
dreampiggy force-pushed the bugfix/uiview_webcache_sdcallbackqueue branch from 9db39a4 to ed1f0f8 Compare November 11, 2024 09:43
@dreampiggy
Introduce SafeAsyncMainThread policy
2f39f8a
This used for user who really need `mainThread` but not `mainQueue`
@dreampiggy dreampiggy changed the title Deprecate dispatch_main_async_safe, UIView+WebCache API now supports SDCallbackQueue and may callback in non-main queue Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread and .safeAsyncMainQueue for different use case Nov 14, 2024
@dreampiggy
Change the SDCallbackQueue to allows easier usage. Only main queue us…
b4c741a
…e `SafeAsyncMainQueue`, others revert back to default value

The implementation don't need complicated check, using object compare is enough
@dreampiggy
dreampiggy force-pushed the bugfix/uiview_webcache_sdcallbackqueue branch from 64f9ffb to b4c741a Compare November 14, 2024 13:35
@dreampiggy

dreampiggy commented Nov 15, 2024

Copy link
Copy Markdown
Contributor Author

Some one point this that we should always use MainThread to check for dispatch. Never use MainQueue

So what's the real correct way ? Why the SDWebImage original author use dispatch_queue_main to check if it's suitable to call the completion block in sync?

@Kyle-Ye

https://twitter.com/KyleSwifter/status/1856704385285566896

Kyle-Ye reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dreampiggy dreampiggy changed the title Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread and .safeAsyncMainQueue for different use case Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread and .safeAsyncMainQueue for different use case, and defaults to MainThread Nov 15, 2024
@dreampiggy dreampiggy changed the title Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread and .safeAsyncMainQueue for different use case, and defaults to MainThread Deprecate dispatch_main_async_safe, introduce two more policy .safeAsyncMainThread (for UIKit diffable data source) and .safeAsyncMainQueue (for most common cases) Feb 20, 2025
@dreampiggy dreampiggy added this to the 5.21.0 milestone Feb 20, 2025
@dreampiggy

dreampiggy commented Feb 20, 2025

Copy link
Copy Markdown
Contributor Author

TLDR

For normal image loading, we use SDCallbackPolicySafeAsyncMainQueue, which only sync when in the main queue. This is for the common case. And I don't want to break exists user's behavior

For UICollectionViewDiffableDataSource, use SDCallbackPolicySafeAsyncMainThread, which don't care about GCD queue but only check main thread.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This was referenced Feb 20, 2025
Image flicker due to async cache when using NSDiffableDataSource #3411
Closed
UICollectionView Compositional Layout + Diffable Datasource Support #2984
Closed
@dreampiggy
dreampiggy merged commit c085d53 into SDWebImage:master Feb 20, 2025
@dreampiggy dreampiggy added the view category Related to UIView Category label Feb 20, 2025
@dreampiggy dreampiggy mentioned this pull request Feb 21, 2025
Change the default callback queue policy to SafeAsyncMainThread, don't need main queue check at all #3797
Merged
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

view category Related to UIView Category

Projects

None yet

Milestone

5.21.0

Development

Successfully merging this pull request may close these issues.

dispatch_main_async_safe issue

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@dreampiggy
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.