Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8725623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:04:45+00:00 2026-06-13T08:04:45+00:00

Both iterators and async methods create a state machine for keeping the state between

  • 0

Both iterators and async methods create a state machine for keeping the state between yield/await operations and every local in your method becomes a field in that instance of the state machine type.

In this talk, Stephen Toub talks about having less local variables in the bodies of async methods is a valid (no micro) optimization if you have lots of await calls. (i.e. if you’re awaiting in a loop)

So in this case, I wonder the performance difference between having 7 locals and having one local which is a Tuple<T1, T2, T3, T4, T5, T6, T7> .

Obviously, it does nothing but to complicate things if there is only one yield in the iterator or only one await in the async method but when it comes to thousands or more, do you think using tuples (or any other type that will wrap your fields) do any good?

Or would that be just another micro-optimization attempt that accomplishes nothing or too less to use?

Edit: Now that I thought it again, it would already be implemented that way if it would do any good, I suppose. Nonetheless, I’m still curious about it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:04:47+00:00Added an answer on June 13, 2026 at 8:04 am

    If you have thousands of await/yield, then something is already very wrong. It should also be noted that the two have different implementations. However, changing to a tuple isn’t adding anything useful, IMO. You are still storing (as state) a single reference in either case, no matter whether that reference is:

    • the iterator instance
    • a captured-variable context
    • a tuple
    • a captured-variable context to a tuple

    But by using a tuple you guarantee you need a new instance any time you need to mutate a variable.

    Tulle can be more interesting when implementing async manually (things like ContinueWith), but I really don’t think it is worth it when using the compiler to provide the implementation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Both methods MyBehavior::CreateSerializer() are not called of some reason, but ReplaceBehavior() method is working.
I want to create a custom container that supports iterators. It looks like this:
For a std::for_each call, is it legal to have both iterators be the end
Motivation C# 5.0 async/await constructs are awesome, unfortunately yet Microsoft only shown a release
How to create an STL object of iterators of template Type? I am trying
std::map find/end both provides const_iterator and iterator, e.g. iterator end (); const_iterator end ()
When the while loop iterates, it skips both if loops and when the q=q->next
Both the events are getting fired at the time onblur event. <%@ Page Language=C#
Both of these frameworks are great, but I've noticed that Knockout likes to point
Both Network.Socket.ByteString and Network.Socket.ByteString.Lazy have a send function. Network.Socket.ByteString has a sendTo function, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.