How to Identify and Remove Dead Code in a Complex Java Project?

0
3
Asked By JavaJuggler88 On

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

Answered By TrafficBalancer On

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.

LegacyCodeGuru -

That's an interesting workaround! It might be a good way to test without impacting service too much.

Answered By CodeCleaner42 On

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!

Answered By DevOpsNinja9 On

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!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.