-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Avoid submaterialization for lazy future and lazy single #31735
Conversation
@@ -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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
single(create).mapAsync(1)(_())?
There was a problem hiding this comment.
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.
close-reopen to retrigger full CI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
References #31729
Same benefit as #31733 but by removing code instead of adding more.
Also covers lazySingle and corresponding methods in Java DSL.