You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.