import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.46k stars 1.56k forks source link

import/no-duplicates performance slow #2746

Open tjx666 opened 1 year ago

tjx666 commented 1 year ago

code:

import fs from 'node:fs/promises';
import os from 'node:os';
import path from 'node:path';
import util from 'node:util';

import { findWorkspacePackagesNoCheck } from '@pnpm/find-workspace-packages';
import consola from 'consola';
import c from 'picocolors';

console.log(fs, path, findWorkspacePackagesNoCheck, consola, c, os, util);

image

Versions:


  System:
    OS: macOS 13.2.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
    Memory: 1.74 GB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.15.0 - ~/Library/Caches/fnm_multishells/87111_1679468379491/bin/node
    npm: 9.6.2 - ~/Library/Caches/fnm_multishells/87111_1679468379491/bin/npm
  npmPackages:
    eslint: ^8.36.0 => 8.36.0 
    eslint-plugin-import": 2.27.5
R1ON commented 1 year ago

I have the same problem :(

Rule                              | Time (ms) | Relative
:---------------------------------|----------:|--------:
import/no-duplicates              | 72224.446 |    63.4%
import/default                    | 31071.649 |    27.3%
indent                            |  2149.804 |     1.9%
no-imports/outside-special-folder |  2124.553 |     1.9%
import/no-unresolved              |  1399.763 |     1.2%
react/no-direct-mutation-state    |   600.695 |     0.5%
import/export                     |   268.659 |     0.2%
import/no-named-as-default-member |   251.551 |     0.2%
react/no-typos                    |   230.053 |     0.2%
react/require-render-return       |   205.671 |     0.2%
ljharb commented 1 year ago

and if you comment out no-duplicates, what happens to the other import rules?

seiyab commented 11 months ago

It might not a problem about a specific rule. For our project, import/extensions is extremely slow consitently.

Rule                                 |  Time (ms) | Relative
:------------------------------------|-----------:|--------:
import/extensions                    | 103423.841 |    64.9%
import/no-extraneous-dependencies    |  19748.530 |    12.4%
import/no-cycle                      |  14308.905 |     9.0%
import/order                         |   2371.498 |     1.5%
import/no-relative-packages          |   1831.405 |     1.1%
@typescript-eslint/naming-convention |   1697.527 |     1.1%
react/no-unstable-nested-components  |   1021.375 |     0.6%
react/function-component-definition  |    915.998 |     0.6%
import/no-unresolved                 |    685.094 |     0.4%
react/prefer-stateless-function      |    638.503 |     0.4%

However, when I turn off import/extensions as https://github.com/import-js/eslint-plugin-import/issues/2746#issuecomment-1654483023 suggests, another rule get extremely slow.

Rule                                 |  Time (ms) | Relative
:------------------------------------|-----------:|--------:
import/no-extraneous-dependencies    | 114140.980 |    77.9%
import/no-cycle                      |  12257.164 |     8.4%
import/order                         |   2212.973 |     1.5%
import/no-relative-packages          |   1627.329 |     1.1%
@typescript-eslint/naming-convention |   1573.758 |     1.1%
react/no-unstable-nested-components  |    963.062 |     0.7%
react/function-component-definition  |    809.087 |     0.6%
import/no-unresolved                 |    678.688 |     0.5%
react/prefer-stateless-function      |    608.823 |     0.4%
react/static-property-placement      |    557.109 |     0.4%

I don't know plugin-import internal but I'm suspicous of something like common setup.

soryy708 commented 1 week ago

Related to ExportMap performance?

But no-duplicates doesn't use ExportMap does it?

ljharb commented 1 week ago

true, but it does invoke the resolver, which in turn uses the ModuleCache, so maybe that's the problem.