Skip to content

Conversation

@cowboyd
Copy link
Member

@cowboyd cowboyd commented Nov 5, 2024

Motivation

Many of the Operations are comprised of a single Effect, and very often a synchronous Effect at that. There is no need to pay any of the overhead for creating a generator when we could just make a simple iterator.

Approach

This introduces a Do() function which takes any effect and converts it automatically into an operation (an effect iterator) so that it can be used anywhere that an operation can be used. The iterator just returns a wrapping effect that captures its result, and then the next time it is called, it returns that result. This gives us better performance and also solves the circular dependency problem inside context.ts

@cowboyd cowboyd requested a review from taras November 5, 2024 16:52
Copy link
Member

@taras taras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you know that it improves performance?

@cowboyd
Copy link
Member Author

cowboyd commented Nov 5, 2024

How do you know that it improves performance?

I'm using this performance suite created by @rixtox https://github.com/cowboyd/async-benchmark/tree/effection-v4

GitHub
Contribute to cowboyd/async-benchmark development by creating an account on GitHub.

Many of the Operations are comprised of a single Effect, and very
often a synchronous Effect at that. There is no need to pay any of the
overhead for creating a generator which has, among other things its
own independent stack frame, when we could just make a simple
iterator.

This introduces a `Do()` operation which takes any effect and converts
it automatically into an operation where it can be used anywhere. This
gives us better performance and also solves the circular dependency
problem inside `context.ts`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants