palantir / palantir-java-format

A modern, lambda-friendly, 120 character Java formatter.
Apache License 2.0
424 stars 45 forks source link

Improvement: Add instrumentation to allow warning on files that take long to format #989

Open MTelling opened 7 months ago

MTelling commented 7 months ago

Before this PR

We have noticed the formatter becomes really slow on functions that nest a lot, causing some files to take +10 seconds to format. A simple refactor can often fix these issues but it can be hard to identify and enforce that files are kept in a shape that formatter formats quickly.

This PR adds instrumentation to file formatting and, if enabled, prints errors to the console for files that exceed the specified threshold.

After this PR

==COMMIT_MSG== Add instrumentation to allow warning on files that take long to format ==COMMIT_MSG==

Possible downsides?

I'd rather fix the formatter here but that might take a lot more time and in places where we've seen issues, the code could use a refactor anyway (deeply nested code is not very pretty).