Skip to content

Conversation

@He-Pin
Copy link
Contributor

@He-Pin He-Pin commented Sep 17, 2022

A follow up of #31372.

refs: #21462

Draft status, just make the test pass and the SupervisionStrategy is not handle

If this is acceptable I will try with Source.fromFuture later in a separated pr.

single source case is already done in : #25242

jmh:run -prof gc -i 5 -wi 5 -f2 -t1 akka.stream.FlatMapConcatBenchmark
for oneElementList:

main branch:
[info] FlatMapConcatBenchmark.oneElementList                                     thrpt   10    379866.207 锟斤拷   4994.706   ops/s
this branch:
[info] FlatMapConcatBenchmark.oneElementList                                     thrpt   10   4807136.226 锟斤拷  49006.261   ops/s

Run with main branch:
image

Run with this branch:
image

@He-Pin He-Pin marked this pull request as draft September 17, 2022 10:09
push(out, elements.head)
removeSource(iterableSource)
} else {
emitMultiple(out, elements, () => removeSource(iterableSource))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not run with the SupervisionStrategy of IterableSource

Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work, it will have to be something more clever, emitMultiple will replace the current handlers and emit until end so would only work for breadth = 1 (flatMapConcat), for merge it will turn it into concat.

There will have to be something more clever wrt combining the current open streams with current iterators, in the queue keeping their state across pulls from downstream for non 0-1 size cases.

@He-Pin He-Pin closed this Sep 19, 2022
@He-Pin He-Pin reopened this Sep 19, 2022

private def handleIterableSource(iterableSource: IterableSource[T]): Unit = {
val elements = iterableSource.elements
if (elements.knownSize == 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

not available in 2.13.x, maybe hasDefiniteSize

Copy link
Contributor

@johanandren johanandren left a comment

Choose a reason for hiding this comment

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

Good one to optimize, but tricky


override def createLogic(enclosingAttributes: Attributes) =
new GraphStageLogic(shape) with OutHandler with InHandler {
override def createLogic(enclosingAttributes: Attributes): GraphStageLogic with InHandler with OutHandler =
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to repeat the type here, we are implementing an abstract method

* creates a [[GraphStageLogic]] which implements the processing logic that ties the ports together.
*/
abstract class GraphStage[S <: Shape] extends GraphStageWithMaterializedValue[S, NotUsed] {
abstract class GraphStage[+S <: Shape] extends GraphStageWithMaterializedValue[S, NotUsed] {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this variance change needed?

def activeSources: Int = sources.size + pendingDirectPushSources

// To be able to optimize for SingleSource without materializing them the queue may hold either
// SubSinkInlet[T] or SingleSource
Copy link
Contributor

Choose a reason for hiding this comment

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

Update comment as well

push(out, elements.head)
removeSource(iterableSource)
} else {
emitMultiple(out, elements, () => removeSource(iterableSource))
Copy link
Contributor

Choose a reason for hiding this comment

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

This won't work, it will have to be something more clever, emitMultiple will replace the current handlers and emit until end so would only work for breadth = 1 (flatMapConcat), for merge it will turn it into concat.

There will have to be something more clever wrt combining the current open streams with current iterators, in the queue keeping their state across pulls from downstream for non 0-1 size cases.

removeSource(iterableSource)
} else if (elements.size == 1) {
push(out, elements.head)
removeSource(iterableSource)
Copy link
Contributor

Choose a reason for hiding this comment

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

Handling the case of known of more than 1 element is missing

@He-Pin
Copy link
Contributor Author

He-Pin commented Sep 19, 2022

Will try to take it further this weekend
Will update it after National day.

@He-Pin
Copy link
Contributor Author

He-Pin commented Jul 30, 2023

was done in #32024

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.

2 participants