prettier/eslint-plugin-prettier

Very slow performance

NullVoxPopuli opened this issue · 8 comments

This issue is the successor to: #304
which was closed after #368.
But I don't think that's enough.

What version of eslint are you using?

❯ yarn eslint -v
v7.32.0

What version of prettier are you using?

❯ yarn list prettier
└─ prettier@2.4.1

What version of eslint-plugin-prettier are you using?

❯ yarn list eslint-plugin-prettier
└─ eslint-plugin-prettier@3.4.1

Please paste any applicable config files that you're using (e.g. .prettierrc or .eslintrc files)
n/a
( there also isn't a reasonable way to paste this here, cause I given up on simple lint configs, and gone with an overrides only approach: https://github.com/NullVoxPopuli/eslint-configs )

I don't have or use a .prettierrc, but have defined the following (in a local project) with the following config:

'prettier/prettier': [
        'error',
        {
          arrowParens: 'always',
          printWidth: 100,
          singleQuote: true,
          trailingComma: 'all',
        },
      ],

What source code are you linting?
Combination of JS, TS, and JSON, but only JS and TS have eslint-plugin-prettier enabled.

What did you expect to happen?

Not have > 20% of time spent on one plugin

What actually happened?

Rule                                                                  | Time (ms) | Relative
:---------------------------------------------------------------------|----------:|--------:
prettier/prettier                                                     | 22398.901 |    85.9%
no-redeclare                                                          |   276.436 |     1.1%
padding-line-between-statements                                       |   242.521 |     0.9%
ember/no-assignment-of-untracked-properties-used-in-tracking-contexts |   178.402 |     0.7%
@typescript-eslint/no-unused-vars                                     |   166.158 |     0.6%
no-unused-vars                                                        |   165.051 |     0.6%
ember/require-computed-property-dependencies                          |   159.632 |     0.6%
ember/no-actions-hash                                                 |   145.305 |     0.6%
ember/no-get                                                          |   129.990 |     0.5%
ember/no-on-calls-in-components                                       |    94.890 |     0.4%

Do you have any stats about how long prettier takes to run over all the files that you lint without going through the eslint bridge.

It is not currently clear if this speed is due to this plugin doing something wrong or because prettier just takes that long.

There's a very real chance that's just how long prettier takes to run over your files, which this bridge can do nothing about.

yeah, prettier itself takes 15s on the same set of files.

I recently discovered https://github.com/XAMPPRocky/tokei
which is orthogonal to all of this. but it runs on many many many many more files, in < 3s.

So... I fear that the answer may be for prettier and eslint to start migrating to rust (or some other system language)

If you’re looking for a code formatter written in Rust that supports JS/TS, check out https://github.com/dprint/dprint

ref: #304 (comment)

This said when using eslint to format codes with prettier, it's slow.

I come up with an idea:

{
  '**/*.{ts,tsx}': [
    (filenames) => {
      const files = [...filenames, ...declarationFiles];
      return `tsc ${files.join(' ')} --noEmit --skipLibCheck`;
    }, // typescript type checking
    "prettier --write", // use prettier to format your code
    `eslint --cache --fix --rule 'prettier/prettier: off'`, // turn off the prettier/prettier rule, make it faster
  ],
}

Not sure if this is the best one, but I think should make it faster. 🥸

Can you help to try latest v4.1.0?

This could be related to that we are running prettier.resolveConfig.sync and prettier.getFileInfo.sync for every file, I'll try to find a better solution for this case, for example cache support at least.

@fisker @sosukesuzuki

Do you think we can benefit from the new prettier's cache? I didn't find any cache content in node_modules/.cache/prettier.

close in favor of #485