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

Significant performance degradation with new json rendering Introduced in 1.11 #634

Closed
recons opened this issue Sep 22, 2024 · 5 comments
Closed
Assignees
Milestone

Comments

@recons
Copy link

recons commented Sep 22, 2024

In our case, we are dealing with a large stream of big objects, which are serialized into json and written to a file. After upgrading to 1.11, we noticed higher execution time, an increase in cpu usage and more time spent in gc.

Below is a minimal code snippet to demonstrate the issue:

fs2.Stream.range(0, 10000000)
     .map(Json.fromInt)
     .covary[IO]
     .through(ast.tokenize)
     .through(wrap.asTopLevelArray)
     .through(render.compact)
     .compile
     .drain
     .timed
     .map(_._1.toMillis.toString())
     .flatMap(IO.println)

On my machine (MBP 16 2019, 2.6 GHz 6-Core Intel Core i7), the above code takes:

  • 1.11: 81257 ms
  • 1.10: 20909 ms

While this isn't a full-fledged analysis, we suspect that the regression is related to the new rendering in 1.11. We plan to stick with version 1.10 for now, but further insight would be appreciated.
Perhaps I'm missing something? Could this performance hit be expected under certain conditions, or is it likely a regression?

@satabin
Copy link
Member

satabin commented Sep 23, 2024

Hi. We changed the rendering in 1.11, which is probably the cause. I am thinking of reverting the compact rendering to what it was in 1.10. The introduced change is too impatfull for this use case.

@recons
Copy link
Author

recons commented Sep 23, 2024

Hi, thanks for your reply.

Unfortunately, it's not just the compact rendering that's been affected. In the same use case, when switching to render.prettyPrint, the process doesn't even complete after 5 minutes. It also produces numerous warnings, such as:

[WARNING] Your app's responsiveness to a new asynchronous event (such as a new connection, an upstream response, or a timer) was in excess of 100 milliseconds. Your CPU is probably starving. Consider increasing the granularity of your delays or adding more cedes. This may also be a sign that you are unintentionally running blocking I/O operations (such as File or InetAddress) without the blocking combinator.

On the other hand, using the deprecated render.pretty takes only 23 seconds and completes without any warnings at all.

@satabin
Copy link
Member

satabin commented Sep 23, 2024

The pretty printer has been entirely changed as well. It looks like some ceding is necessary in its implementation. I will investigate.

@satabin satabin added this to the 1.11.2 milestone Sep 23, 2024
@satabin satabin self-assigned this Sep 23, 2024
@satabin
Copy link
Member

satabin commented Oct 9, 2024

Hi @recons,

I ran some benchmarks and identified several sources for slow downs. I am now working on fixing them. I will open a PR as soon as I have something usable, so that you can try it with your use case.

@satabin
Copy link
Member

satabin commented Dec 10, 2024

Fixed by #641.

@satabin satabin closed this as completed Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants