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

LFFormatter is slow #1342

Closed
petervdonovan opened this issue Aug 31, 2022 · 6 comments · Fixed by #1788 or #1779
Closed

LFFormatter is slow #1342

petervdonovan opened this issue Aug 31, 2022 · 6 comments · Fixed by #1788 or #1779
Assignees
Labels
Milestone

Comments

@petervdonovan
Copy link
Collaborator

This is an issue extracted from the review of #1227.

Code formatting should be fast. This is feasible because formatting should be linear in the length of a file, and file lengths should always be bounded in practice (e.g., no more than a few thousand lines). It is necessary because it is common for programmers to set VS Code to "format on save" so that the code on their screen is never ugly for long, even if they are too lazy to format anything by hand.

However, the algorithm used in LFFormatter is not fast, nor is it even linear in the length of a file. It has undergone zero performance optimization because it is good enough to format the toy examples in our test suite and because when I wrote it, I was primarily concerned with rapidly setting an example of how LF files should be formatted. It should be easy to optimize the algorithm and at least give it an acceptable time complexity.

If we cannot make the algorithm faster than a typical human reaction time for all non-pathological files, then we should provide a way to cancel the formatting process in the IDE. This is easy to do using the cancel indicator object.

@petervdonovan
Copy link
Collaborator Author

While working on #1389, I noticed that the spotlessLinguaFrancaApply task can take quite a while. I found myself waiting many minutes before any changes became visible in the file system. This can be frustrating if you don't know what is going on. This is probably either because I invoke the LFF jar and start up the JVM for each test or because I did not worry about about time complexity in the formatter. The person-hours saved by taking these shortcuts were worth it for me.

@petervdonovan
Copy link
Collaborator Author

Update -- I think the real problem is that the Spotless format task restarts the jar for every file, which is bad. This should be an easy fix.

@cmnrd cmnrd added this to the 0.5.0 milestone May 23, 2023
@cmnrd
Copy link
Collaborator

cmnrd commented May 23, 2023

This problem became pressing now as we now expect contributors to run ./gradlew spotlessApply before checking in new code. This runs 20 minutes on my machine...

I added this issue to the 0.5.0 milestone as I think it needs to be addressed ASAP.

@petervdonovan
Copy link
Collaborator Author

petervdonovan commented May 23, 2023

A fix for this is in progress. Until it is merged I recommend to

  • use ./gradlew spotlessJavaApply to format only the Java files using Spotless
  • use lff to format the LF files that were modified. IIRC lff accepts globs. (edit: bash accepts globs).

@cmnrd
Copy link
Collaborator

cmnrd commented May 24, 2023

Can we configure spotless such that it does not format the LF files when running the gradle task? I mean, we do have lff and if it is the preferred method for formatting files is lff, then why have a redundant gradle task? We can quite as well run ./gradlew runLff --args .

@petervdonovan
Copy link
Collaborator Author

Spotless provides some features, such as ensuring that the formatter is idempotent and checking that files are formatted, without actually formatting them. In order for these to work, we have to plug the LF formatter into Spotless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants