Skip to content

Conversation

@taooceros
Copy link
Member

Since most of the image will be stored on cache, so synchronous action will be done quite significant for SetImage method in ResultViewModel, using ValueTask instead of Task can avoid those cost.

@jjw24
Copy link
Member

jjw24 commented Jan 4, 2021

do we know if this will bring a benefit? (https://stackoverflow.com/questions/43000520/why-would-one-use-taskt-over-valuetaskt-in-c)

whats the improvement here using ValueTask and do we know for sure is worth it?

@taooceros
Copy link
Member Author

It can avoid the task allocation since most of our image processing is sync, although wrapped in an async action. If the image is in the cache, it will run synchronizely. So there will be some waste when using task.
The copy issue isn't large because the value task in lazy async will only be assessed as a field, so it won't be copied. It will only be copied at the first time using the factory to create the task.
I don't believe it will bring significant performance boost or memery reduce, but value task should be a better usage here.

@taooceros
Copy link
Member Author

Use Task when something is usually or always going to be genuinely asynchronous, i.e. not immediately complete; use ValueTask when something is usually or always going to be synchronous, i.e. the value will be known inline; also use ValueTask in a polymorphic scenario (virtual, interface) where you can't know the answer.

@jjw24 jjw24 added enhancement New feature or request review in progress Indicates that a review is in progress for this PR and removed review in progress Indicates that a review is in progress for this PR labels Jan 5, 2021
@jjw24 jjw24 merged commit 3aa678b into Flow-Launcher:dev Jan 6, 2021
@taooceros taooceros deleted the LazyAsyncWithValueTask branch January 6, 2021 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants