vscode-eslint: Saving files with eslint code action is really slow

Type: Performance Issue

when I add eslint code action on saving, saving files becomes really slow

"editor.codeActionsOnSave": {
    "source.fixAll": true,
}

I ran the Bisect and found that the problem comes from eslint extension

here are my eslint configs

module.exports = {
  parser: '@typescript-eslint/parser',
  extends: [
    'plugin:react/recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:prettier/recommended',
    'plugin:import/errors',
    'plugin:import/warnings',
    'plugin:import/typescript',
    'plugin:storybook/recommended',
  ],
  plugins: ['simple-import-sort', 'react-hooks'],
  parserOptions: {
    ecmaVersion: 2018,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
    },
  },
  overrides: [
    {
      files: ['*.js', '*.jsx'],
      rules: {
        '@typescript-eslint/explicit-function-return-type': 0,
        '@typescript-eslint/explicit-member-accessibility': 0,
        '@typescript-eslint/no-var-requires': 0,
      },
    },
  ],
  rules: {
    'react/jsx-uses-react': 'off',
    'react/react-in-jsx-scope': 'off',
    'no-console': 2,
    'react/prop-types': 0,
    'simple-import-sort/imports': 'error',
    '@typescript-eslint/no-use-before-define': [2, { variables: false }],
    '@typescript-eslint/interface-name-prefix': 0,
    '@typescript-eslint/explicit-function-return-type': 0,
    '@typescript-eslint/explicit-module-boundary-types': 0,
    '@typescript-eslint/no-unused-vars': ['error', { ignoreRestSiblings: true }],
    'react-hooks/rules-of-hooks': 'error',
    'react-hooks/exhaustive-deps': 'warn',
    '@typescript-eslint/no-unnecessary-condition': ['error', { allowConstantLoopConditions: true }],
  },
  ignorePatterns: ['**/generated'],
  settings: {
    react: {
      version: 'detect',
    },
    'import/resolver': {
      node: {
        extensions: ['.ts', '.tsx', '.js', '.jsx'],
      },
    },
  },
};

Extension version: 2.2.6 VS Code version: Code 1.72.2 (d045a5eda657f4d7b676dedbfa7aab8207f8a075, 2022-10-12T22:16:30.254Z) OS version: Darwin x64 22.1.0 Modes: Sandboxed: No

System Info
Item Value
CPUs Intel® Core™ i9-9880H CPU @ 2.30GHz (16 x 2300)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 4, 4, 4
Memory (System) 16.00GB (3.02GB free)
Process Argv –crash-reporter-id 2a886961-8a82-4e90-b3e3-ee50e266bb8a
Screen Reader no
VM 0%
Process Info
CPU %	Mem MB	   PID	Process
   17	   197	 71754	code main
    0	    82	 71757	   gpu-process
    0	    16	 71760	   utility-network-service
    0	   164	 71761	   window (player.rs — lp-bevy-tutorial)
    0	   508	 71762	   window (settings.json — BY-1933-add-drawer-component)
    0	   213	 71853	   extensionHost
    0	    16	 71992	     /Users/salamaashoush/.vscode/extensions/rust-lang.rust-analyzer-0.3.1248-darwin-x64/server/rust-analyzer
    0	    16	 72346	       /Users/salamaashoush/.rustup/toolchains/nightly-x86_64-apple-darwin/libexec/rust-analyzer-proc-macro-srv
    0	    33	 72489	     /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --ms-enable-electron-run-as-node /Users/salamaashoush/.vscode/extensions/streetsidesoftware.code-spell-checker-2.10.1/packages/_server/dist/main.js --node-ipc --clientProcessId=71853
    0	   246	 71855	   shared-process
    0	    49	 71856	     ptyHost
    0	     0	 72128	       /usr/local/bin/fish -l
    0	     0	 72153	       /usr/local/bin/fish -l
    0	    16	 71946	     fileWatcher
    0	    49	 77530	     fileWatcher
    0	     0	 77854	     /bin/ps -ax -o pid=,ppid=,pcpu=,pmem=,command=
    0	    82	 75421	   utility
    0	    82	 77527	   issue-reporter
    0	   573	 77528	   extensionHost
    0	   180	 77551	     /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --ms-enable-electron-run-as-node --max-old-space-size=3072 /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js --serverMode partialSemantic --useInferredProjectPerProjectRoot --disableAutomaticTypingAcquisition --cancellationPipeName /var/folders/q7/z945j8vs7bq29s2zd6qbxdyh0000gn/T/vscode-typescript501/4c6703e1833fef8bf57c/tscancellation-b149849d0c5be99878a4.tmp* --globalPlugins typescript-styled-plugin,typescript-svelte-plugin,@vsintellicode/typescript-intellicode-plugin,ms-vsintellicode-typescript --pluginProbeLocations /Users/salamaashoush/.vscode/extensions/styled-components.vscode-styled-components-1.7.5,/Users/salamaashoush/.vscode/extensions/svelte.svelte-vscode-106.2.0,/Users/salamaashoush/.vscode/extensions/visualstudioexptteam.vscodeintellicode-1.2.28,/Users/salamaashoush/.vscode/extensions/visualstudioexptteam.vscodeintellicode-1.2.28 --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc
    1	   541	 77552	     /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --ms-enable-electron-run-as-node --max-old-space-size=3072 /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/tsserver.js --useInferredProjectPerProjectRoot --enableTelemetry --cancellationPipeName /var/folders/q7/z945j8vs7bq29s2zd6qbxdyh0000gn/T/vscode-typescript501/4c6703e1833fef8bf57c/tscancellation-d7029d0136100a47dda5.tmp* --globalPlugins typescript-styled-plugin,typescript-svelte-plugin,@vsintellicode/typescript-intellicode-plugin,ms-vsintellicode-typescript --pluginProbeLocations /Users/salamaashoush/.vscode/extensions/styled-components.vscode-styled-components-1.7.5,/Users/salamaashoush/.vscode/extensions/svelte.svelte-vscode-106.2.0,/Users/salamaashoush/.vscode/extensions/visualstudioexptteam.vscodeintellicode-1.2.28,/Users/salamaashoush/.vscode/extensions/visualstudioexptteam.vscodeintellicode-1.2.28 --locale en --noGetErrOnBackgroundUpdate --validateDefaultNpmLocation --useNodeIpc
    0	    82	 77553	       /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --ms-enable-electron-run-as-node /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typingsInstaller.js --globalTypingsCacheLocation /Users/salamaashoush/Library/Caches/typescript/4.8 --enableTelemetry --typesMapLocation /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/node_modules/typescript/lib/typesMap.json --validateDefaultNpmLocation
    0	   115	 77588	     /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --ms-enable-electron-run-as-node /Users/salamaashoush/.vscode/extensions/streetsidesoftware.code-spell-checker-2.10.1/packages/_server/dist/main.js --node-ipc --clientProcessId=77528
    0	    98	 77788	     /Applications/Visual Studio Code.app/Contents/Frameworks/Code Helper.app/Contents/MacOS/Code Helper --ms-enable-electron-run-as-node /Applications/Visual Studio Code.app/Contents/Resources/app/extensions/json-language-features/server/dist/node/jsonServerMain --node-ipc --clientProcessId=77528
Workspace Info
|  Window (settings.json — BY-1933-add-drawer-component)
|  Window (player.rs — lp-bevy-tutorial)
|    Folder (BY-1933-add-drawer-component): 4336 files
|      File types: tsx(1323) ts(1085) svg(294) js(145) ttf(104) log(75)
|                  json(70) woff(70) woff2(70) png(32)
|      Conf files: package.json(20) tsconfig.json(19) settings.json(2)
|                  dockerfile(1)
|    Folder (lp-bevy-tutorial): 5414 files
|      File types: o(939) json(551) timestamp(550) d(510) rmeta(456) rlib(240)
|                  bc(141) ll(19) rs(14) dylib(14)
|      Conf files:;
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vstes516:30244333
vslsvsres303:30308271
pythonvspyl392:30443607
vserr242cf:30382550
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscoreces:30445986
pythondataviewer:30285071
vscod805:30301674
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593cf:30376535
pythonvs932:30410667
cppdebug:30492333
vsclangdf:30486550
c4g48928:30535728
dsvsc012:30540252
azure-dev_surveyone:30548225
2144e591:30553903
pyindex848cf:30577861
nodejswelcome1:30587005
40g7c324:30573242

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 15 (7 by maintainers)

Most upvoted comments

First of all, you’re using the setting to auto-fix all (both linting and non-ESLint related) problems when saving a file. If you only want to auto-fix ESLint problems, try using:

"editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
}

Another optimization is to set "eslint.codeActionsOnSave.mode": "problems". The setting description says that it will “fix only reported problems that have non-overlapping textual edits. This option runs a lot faster.”: https://github.com/microsoft/vscode-eslint/blob/4b92c12af15d41f76417bde9571cb56f08ec3d0f/package.json#L406-L419

Alternatively, you can also try explicitly listing the linting rules that you want to auto-fix with "eslint.codeActionsOnSave.rules". The README has more information about how you can configure this setting. https://github.com/microsoft/vscode-eslint/blob/4b92c12af15d41f76417bde9571cb56f08ec3d0f/package.json#L420-L433

The slowdown is usually caused by specific Eslint rules and unfortunately there is in most of the times nothing the extension itself can do about it. The recommended way to address this is to:

  • enable debugging to see which rule is slow. You can do this by using the eslint.debug setting and inspect the output in the ESLint channel.
  • exclude the rule using the eslint.codeActionsOnSave.rules setting

If none of the rules is slow can you please provide us with a GitHub repository we can clone that demos the slowness.

This maybe could use

  • some user-visible warnings “ESLint taking too long”
  • disabling non-autofix rules on non-last iteration
  • suggesting to profile ESLint rules

image <small> ^ a useless rule taking up over 50% of time</small>

Also IMO the first suggestion the user should be able to find in this thread should be

Please run 
$ TIMING=1 DEBUG=eslint:cli-engine yarn eslint src/components/NewNode.vue --fix
and disable that useless rule which is using 90% of the time

I have the same problem

I guess it may be caused by a combination of:

  • a big .vue file, ~300 lines
  • heavy rules ( plugin:vue/vue3-recommended + @vue/eslint-config-standard-with-typescript or @vue/eslint-config-airbnb-with-typescript )
  • big typescript libraries in global (quasar)
  • slow processor (because discharged laptop battery)
  • causing long formatting times (~3000ms per pass)
  • with big amount of fixes, requiring 10 passes, causing 30 seconds for first fix
  • with another formatter on top of that, requiring more then one pass for every save
       "editor.defaultFormatter": "Vue.volar",
       "_editor.codeActionsOnSave": ["source.formatDocument", "source.fixAll.eslint"],
    

Found out why it is slow in my case, we recently added @typescript-eslint/no-unnecessary-condition rule, and it required us to set parserOptions.project in my eslint configs, and when I remove those it works just fine