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

migrate json4s, json4s-native, json4s-jackson to cats-effect 3 #3885

Merged
merged 5 commits into from Nov 24, 2020

Conversation

yanns
Copy link
Contributor

@yanns yanns commented Nov 19, 2020

I'd like to enable some tests to check #3871

Now that we are using Concurrent instead of Sync, we cannot use F.delay anymore.
I'm not sure that would be the right approach here.

I've started with pure.
As the parsing of a json can take CPU time, should we signal it that some way so that maybe a new thread should be used for it? Could this block a fiber?

Should we use something different from F.pure()? F.unit.as()?

build.sbt Outdated
@@ -33,7 +33,7 @@ lazy val modules: List[ProjectReference] = List(
// boopickle,
// circe,
// json4s,
Copy link
Member

Choose a reason for hiding this comment

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

You'll want to uncomment this line, too. You're already tackling this common module.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 28 to 31
F.pure(
Try(reader.read(json)).toEither
.leftMap[DecodeFailure](e => InvalidMessageBodyFailure("Could not map JSON", Some(e)))
))
Copy link
Member

Choose a reason for hiding this comment

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

Yes, F.pure is correct here. I think the old delay was capturing exceptions.

This could be microoptimized and avoid the allocation of a Try with a regular old try/catch expression.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thx for the feedback.
I was not sure if a good old try / catch block was an ok-style in https.
I'll change that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rossabaker
Copy link
Member

I wouldn't flag things that take CPU time. We want this executing on one of the CPU bound pools, sized to one per core. It's blocking IO that we want to shift to blocking pools, where it's more typical to use a cached (or at least larger) thread pool for things not contending for the CPU.

@rossabaker rossabaker added this to To do in Cats Effect 3 via automation Nov 19, 2020
@rossabaker rossabaker moved this from To do to In Progress in Cats Effect 3 Nov 19, 2020
@yanns
Copy link
Contributor Author

yanns commented Nov 19, 2020

I've also activated json4sjackson that does not need any further changes: d4f2307

Copy link
Member

@rossabaker rossabaker left a comment

Choose a reason for hiding this comment

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

I don't think try/catch is bad when wrapping a library that fails by throwing. I think it's bad when we fail by throwing.

If you're just wrapping success in Right and failure in Left, there is Either.catchNonFatal with import cats.implicits._ that would hide the try and catch. You could use that here, but then you'd need to leftMap it. I think what you've done is good, with a small tweak below.

F.pure {
try Right(reader.read(json))
catch {
case e: Exception => Left(InvalidMessageBodyFailure("Could not map JSON", Some(e)))
Copy link
Member

Choose a reason for hiding this comment

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

I'd go with NonFatal(e) instead of e: Exception here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rossabaker rossabaker changed the title migrate json4s-native to cats-effect 3 migrate json4s, json4s-native, json4s-jackson to cats-effect 3 Nov 20, 2020
@rossabaker rossabaker merged commit 3f8c755 into http4s:cats-effect-3 Nov 24, 2020
Cats Effect 3 automation moved this from In Progress to Done Nov 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants