Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid submaterialization for lazy future and lazy single #31735

Conversation

johanandren
Copy link
Member

References #31729

Same benefit as #31733 but by removing code instead of adding more.

Also covers lazySingle and corresponding methods in Java DSL.

@@ -534,7 +534,7 @@ object Source {
* the laziness and will trigger the factory immediately.
*/
def lazySingle[T](create: () => T): Source[T, NotUsed] =
lazySource(() => single(create())).mapMaterializedValue(_ => NotUsed)
single(()).map(_ => create()).withAttributes(DefaultAttributes.lazySingle)
Copy link
Member

Choose a reason for hiding this comment

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

single(create).map(_())?

val f = create()
future(f)
}.mapMaterializedValue(_ => NotUsed)
single(()).mapAsyncUnordered(1)(_ => create()).withAttributes(DefaultAttributes.lazyFuture)
Copy link
Member

@He-Pin He-Pin Nov 16, 2022

Choose a reason for hiding this comment

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

single(create).mapAsync(1)(_())?

Copy link
Member Author

Choose a reason for hiding this comment

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

We optimize away mapAsync(1) to unordered behind the scenes since that is cheaper, so this just shortcuts directly there.

@johanandren
Copy link
Member Author

close-reopen to retrigger full CI

@johanandren johanandren reopened this Nov 16, 2022
Copy link
Member

@patriknw patriknw left a comment

Choose a reason for hiding this comment

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

LGTM

@johanandren johanandren merged commit a8ee6fa into akka:main Nov 17, 2022
@johanandren johanandren deleted the wip-31733-avoid-materialization-for-future-source branch November 17, 2022 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants