GorNishanov / coroutines-ts

20 stars 2 forks source link

Allow resume functions to return values #27

Open imoldfella opened 6 years ago

imoldfella commented 6 years ago

Allow coroutine resume functions with type value_type (*_Resume_fn)(void ) The current resume function void (*_Resume_fn)(void) reduces performance for a significant subset of generators compared to macro based coroutines. We should allow resume functions to take advantage of fast register return conventions.

Create coroutine_handle_fast It would use intrinsic size_t _coro_resume_fast(_Ptr);

Code generation for _coro_resume_fast:

  1. co_yield expr would no longer equate to co_await p.yield_value(x), but would suspend and return the value directly.
  2. co_return or completing the coroutine would return p.sentinel_value();
  3. for coroutines returning types larger than size_t, the return value would be a pointer with 0 for the sentinel.

A benchmark that shows performance degradation compared to macro based coroutines is at https://gist.github.com/imoldfella/ea264e146df67884056da0af1e61964f