openrewrite / openrewrite/rewrite

Performance issue with classpath scanning

Open
#4,051 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement performance
Dominant language
Java
Stars
3.7k
Forks
570
Avg merge
13h 12m
Merged PRs (30d)
261

Description

What problem are you trying to solve?

When running OpenRewrite on larger code bases, with many recipes enabled, I would normally assume it uses all the available cores while it runs. It doesn't. It rather produces a pattern of short spikes (of almost full CPU usage) followed by longer parts of ~30% CPU usage on my multi-core Windows machine.

Attaching a profiler makes me think this is entirely related to the classpath scanning. What I can see

  • the classpath library methods accumulate hours of runtime
  • a huge amount of the classpath scanning runtime is caused by calls to the file system (which is extremely slow on Windows compared to Linux, especially if some antivirus tool is enabled)

I therefore believe that at least on Windows the runtime is dominated by ongoing repetitions of

  • slow classpath scanning
  • short recipe execution

Describe the solution you'd like

This could potentially be improved by splitting the scanning and the analysis into separate runnables executed by 2 different threadpools (where a finished scanning thread would start a recipe thread). In theory this would lead to the classpath scanning running almost all the time (limited by the file system performance and the antivirus stuff), and refactorings being triggered as often as possible in between.

This would still not lead to full CPU usage probably, but at least to higher CPU usage.

Have you considered any alternatives or workarounds?

I have not yet understood whether or not the classpath scanning could eventually be reduced as such. That would of course be an even better solution.

Are you interested in contributing this feature to OpenRewrite?

Maybe. Not sure if I can actually rework the code in this manner. Currently I see this issue more as a discussion about potential improvements.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Start by reproducing the classpath-scanning and recipe-execution pattern on Windows with a profiler, then trace the classpath library calls and filesystem work. Done would require a defined, measured performance improvement and agreement on whether scanning reduction or concurrent execution is the intended direction.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.