Giter Club home page Giter Club logo

Comments (2)

0x804d8000 avatar 0x804d8000 commented on May 5, 2024

Not planned yet.

The main reason is that the compiler we're using internally (GCC 8) does not support C++20 coroutine. That means we won't be able to test coroutine support throughly in production environment (were it implemented).

I have't looked deeply enough into C++20 coroutine. The following is based on my preliminary understanding.

Were it to be implemented, I'd expect operator co_await overload for Future<T> to be provided. This way the following should be possible:

Future<...> AsyncDoSomething() {
  co_await some_client.AsyncDoSomeOtherThing();
}

However, I don't see much point in doing this, when compared with:

... DoSomething() {
  some_cient.DoSomeOtherThing();
}

The reason is that, to permit concurrent packet deserialization, the framework nonetheless needs to use a dedicated fiber for each request.

Therefore we always have one dedicated stack for each request, regardless whether we're using a stackless coroutine to handle it, or handling it directly in fiber. This ruins the main point of using C++20 coroutine (allocating state on heap and avoid using a stack).

Besides, by using a dedicated stack (which is allocated quickly enough in fast path, using our object pool), we can (hopefully) allocate most states (ignoring indirect allocations done by containers) simply by adjusting the stack pointer, without incurring calls to memory allocator. This is generally a performance gain. To the contrary, C++20 coroutine would require the compiler to do one heap allocation for each call to coroutine (unless the compiler is able to optimize that away, in certain cases).

That said, I do see a point in supporting waiting for coroutine result in fiber though, such as:

flare::fiber::WaitOnAwaitable(some_cpp20_async_read_function());

This would allow us to interoperate with libraries using C++20 coroutine, once they're widely spreaded.

I'd expect this to be done once we upgraded our compiler to a more recent one. This should be trivially implementable using an approach similar to cppcoro::sync_wait (using fiber-friendly synchronization primitives).

(Here I'm assuming the coroutine does "return" only once. For generator-alike coroutines, as far as I understand
it, it's need no support from the underlying framework.)

from flare.

npuichigo avatar npuichigo commented on May 5, 2024

Thanks for your detailed reply. I will read the code to get a deeper understanding.

from flare.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.