organize-imports-cli icon indicating copy to clipboard operation
organize-imports-cli copied to clipboard

don't load all files in a project upfront

Open AlabasterAxe opened this issue 2 years ago • 1 comments

One thing I noticed was that for formatting a single file in a large project, organize-imports-cli could be very slow. This PR just doesn't do that loading upfront so that it's quicker to organize imports for a small set of files in a large codebase.

My Tests:

  • already organized imports: .96s (this PR) vs 25.02s (master)
  • 1 unused import 1 transposed import: 2.11s (this PR) vs 26.31 (master)

My assessment was that the ordering change in the snapshot was harmless because the fundamental behavior was unchanged but let me know if that's a real failure.

AlabasterAxe avatar Jun 13 '22 15:06 AlabasterAxe

Hey @thorn0! I noticed some slowness when formatting a single file for my git check and I saw that it's always loading the whole project upfront. Was thinking this could be a useful change. AFAIK this shouldn't affect tsconfig based formatting much because you're still calling project.getSourceFiles() explicitly in that case.

AlabasterAxe avatar Jun 13 '22 15:06 AlabasterAxe