Hey everyone! I'm a senior developer who recently joined a team working with a large Java codebase (around 500,000 lines across 30 different services), mostly written by various contractors over time. We're trying to make sense of the complexities and often find ourselves on wild goose chases due to unused code paths caused by certain `if` statements that always seem to evaluate the same way for almost all accounts. It would greatly help our productivity if we could figure out which methods have actually been called in the past month.
I've come across a few tools:
- **Jacoco**: It provides detailed coverage data, but I've heard it's too heavy for production use.
- **JFR**: Mainly for profiling, but I'm not sure it provides the info we need.
- **AspectJ**: This might be a solution, as it allows low-sampling to avoid performance hits, but I'd need to specify which methods to instrument.
Getting approval for any tool will likely be challenging, so I'm looking to set up a lightweight QA proof of concept. Any tips on how to tackle this would be super helpful! We also have a Datadog subscription if that influences suggestions.
3 Answers
If you want to use Jacoco without the full overhead, consider creating a separate instance of your apps with Jacoco enabled. You can direct a small amount of traffic (like 1-5%) to this instance. It's a bit clunky, but it might give you the coverage data you need without disrupting production.
I feel you on the stress of dealing with dead code. I haven’t tackled this myself, but I read about how Facebook automates their dead code cleanup—might be worth checking out their approach over on their engineering blog!
Azul Intelligence Cloud could be a good fit for tracking down unused code. They have tools designed specifically for this purpose. Definitely take a look at what they offer!
That's an interesting workaround! It might be a good way to test without impacting service too much.