lingua-franca icon indicating copy to clipboard operation
lingua-franca copied to clipboard

`LFFormatter` is slow

Open petervdonovan opened this issue 2 years ago • 0 comments

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 avatar Aug 31 '22 22:08 petervdonovan