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

Optimize the **Java** Flow interop #3130

Merged
merged 16 commits into from
May 12, 2023
Merged

Conversation

BalmungSan
Copy link
Contributor

@BalmungSan BalmungSan commented Feb 7, 2023

Follow up of #3102

Copy link
Contributor Author

@BalmungSan BalmungSan left a comment

Choose a reason for hiding this comment

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

Some questions:

  1. Was just moving the files enough for cross-compiling?
  2. For some reason Scala 3 didn't like my covariant State so I had to make it invariant which was a real PITA.
  3. I guess the ClassTag change is a non-go... but then, what should we do?

@BalmungSan BalmungSan marked this pull request as ready for review February 27, 2023 04:59
@BalmungSan BalmungSan requested review from diesalbla and armanbilge and removed request for diesalbla and armanbilge February 27, 2023 04:59
@armanbilge
Copy link
Member

  1. No, we should also run the tests to check that it actually works (although not the TCK ones, since those won't cross-compile). When I checked this the current API was using stuff that doesn't cross-compile. Not sure if that's still the case after your changes.

  2. 🙃

  3. Why do we need ClassTag now? The answer is, don't need it 😂

@BalmungSan BalmungSan changed the title WIP: Optimize the **Java** Flow interop Optimize the **Java** Flow interop Feb 27, 2023
Comment on lines 137 to 138
override def request(n: Long): Unit =
if (canceled.get() ne null) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this canceled check really doing anything useful?

Copy link
Member

Choose a reason for hiding this comment

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

Oh, yes it is, this comment would almost be more helpful here.

// According to the spec, it's acceptable for a concurrent cancel to not
// be processed immediately, but if you have synchronous
// `cancel(); request()`,
// then the request must be a NOOP.
// See https://github.com/zainab-ali/fs2-reactive-streams/issues/29
// and https://github.com/zainab-ali/fs2-reactive-streams/issues/46

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, that was the original place of the comment, I just polished it a little.
I can move it if you prefer, the thing is that it also affects cancel, and well both methods are close together.

@BalmungSan BalmungSan requested a review from armanbilge April 3, 2023 18:11
@armanbilge armanbilge closed this Apr 10, 2023
@armanbilge armanbilge reopened this Apr 10, 2023
Those comments justify that having an Array inside the State AtomicReference is safe; since they will never be concurrently modified.
Copy link
Member

@armanbilge armanbilge left a comment

Choose a reason for hiding this comment

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

The diff was horrible, but when viewed standalone the new implementations are quite elegant. Thanks for bearing with me 😇

.repeatEval(dequeue1)
.unNoneTerminate
.unchunks
.asInstanceOf[Stream[F, A]] // This cast is safe, since all elements come from onNext(a: A).
Copy link
Member

Choose a reason for hiding this comment

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

I tossed and turned on this for several nights but in the end I think it's a win. Besides making it easy to use the Array-based buffer, it also allowed us to remove the type parameter from the state machine. Basically, in this unusual case I think threading the type parameter through the implementation was less ergonomic than "pre-erasing" it.

@armanbilge armanbilge merged commit deb2e2f into typelevel:main May 12, 2023
@BalmungSan BalmungSan deleted the improve-flow branch May 12, 2023 13:46
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