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

execute Task on ImagePipeline DispatchQueue using executorPreference #815

Conversation

georgesjamous
Copy link

The ImagePipeline is currently creating a Task and then immediately switching to its internal queue. This results in unnecessary context switching from the Task’s originating queue to the pipeline’s internal queue.

So, to optimize this and reduce this overhead, we can leverage a custom Task Executor introduced in iOS 18 to ensure that the Task's queue pool chooses the internal queue directly, thus improving performance and minimizing context switching.

Note:

I have not added a specific Test that validate this workflow, as in, the Task is executed on the executer's queue. This is because the current test stack in Nuke is large and I could not figure out exactly with the limited time I have, how to leverage current components to write the tests.

I will leave it here, and hopefully, If needed, another, more codebase knowledgeable contributor can implement a test for it.

The ImagePipeline is currently creating a Task and then switching to its internal queue. This results in unnecessary context switching from the Task’s originating queue to the pipeline’s internal queue. To optimize this, we can leverage a custom Task Executor introduced in iOS 18. This change ensures that the Task executes directly on the ImagePipeline’s DispatchQueue, reducing overhead and improving performance by minimizing context switches.
@kean
Copy link
Owner

kean commented Sep 23, 2024

Hey, that's a excellent suggestion. It pained me to add this extra hop for the sake of supporting Swift Concurrency.

I have a separate branch where these classes are completely redesigned using actors. It should remove this extra thread hop and a few minor ones during processing. I'm planning to release a beta sometime next month. With that in mind, I don't think it's worth adding something to Nuke 12, but I haven't fully investigated it.

@georgesjamous
Copy link
Author

Hey @kean , sure it makes sense. Feel free to close it if you think it's not necessary

@kean
Copy link
Owner

kean commented Sep 25, 2024

I'm not entirely sure but I'm leaning towards keeping the current production as is and focusing on Nuke 13. There is still quite a bit work to do, but I'm close to release the first beta.

@kean kean closed this Oct 12, 2024
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.

2 participants