daidodo / format-imports-vscode

Format imports and exports for JavaScript and TypeScript in VS Code.
https://marketplace.visualstudio.com/items?itemName=dozerg.tsimportsorter
MIT License
62 stars 5 forks source link

Save is slow #27

Closed Zefling closed 3 years ago

Zefling commented 3 years ago

Describe the bug Save is much slower when the extension is enabled

To Reproduce Just use save

Expected behavior A save that is done without too much slowing down.

Actual behavior The save is slow, in some cases it is necessary to do 2 saves.

OS (please complete the following information):

VS Code (please complete the following information):

tsconfig.json (if any)

{
    "extends": "tslint:recommended",
    "linterOptions": {
      "exclude": [
        "**/*.notslint.ts"
      ]
    },
    "rules": {
      "array-type": false,
      "arrow-parens": false,
      "deprecation": false,
      "component-class-suffix": true,
      "contextual-lifecycle": true,
      "directive-class-suffix": false,
      "directive-selector": [
        true,
        "camelCase"
      ],
      "component-selector": [
        true,
        "element",
        "kebab-case"
      ],
      "import-blacklist": [
        true,
        "rxjs/Rx"
      ],
      "interface-name": false,
      "max-classes-per-file": false,
      "max-line-length": [
        true,
        120
      ],
      "member-access": false,
      "member-ordering": [
        true,
        {
          "order": [
            "static-field",
            "instance-field",
            "static-method",
            "instance-method"
          ]
        }
      ],
      "no-consecutive-blank-lines": false,
      "no-console": [
        true,
        "debug",
        "info",
        "time",
        "timeEnd",
        "trace"
      ],
      "no-empty": false,
      "no-inferrable-types": false,
      "no-non-null-assertion": true,
      "no-redundant-jsdoc": false,
      "no-switch-case-fall-through": true,
      "no-use-before-declare": true,
      "no-var-requires": false,
      "object-literal-key-quotes": false,
      "object-literal-sort-keys": false,
      "ordered-imports": false,
      "quotemark": [
        true,
        "single",
        "avoid-escape"
      ],
      "trailing-comma": false,
      "no-conflicting-lifecycle": false,
      "no-host-metadata-property": true,
      "no-input-rename": false,
      "no-inputs-metadata-property": true,
      "no-output-native": false,
      "no-output-on-prefix": false,
      "no-output-rename": false,
      "no-outputs-metadata-property": true,
      "template-banana-in-box": true,
      "template-no-negated-async": true,
      "use-lifecycle-interface": false,
      "use-pipe-transform-interface": true,
      "no-angle-bracket-type-assertion": false,
      "arrow-return-shorthand": false,
      "no-namespace": false,
      "interface-over-type-literal": false,
      "adjacent-overload-signatures": false,
      "one-variable-per-declaration": false,
      "ban": false,
      "ban-types": false,
      "no-string-literal": false,
      "prefer-for-of": false,
      "object-literal-shorthand": false,
      "space-before-function-paren": false,
      "only-arrow-functions": false,
      "semicolon": [
        true,
        "always"
      ],
      "whitespace": [
        true,
        "check-branch",
        "check-decl",
        "check-operator",
        "check-separator",
        "check-type"
      ],
      "import-destructuring-spacing": true,
      "framework-underscore-private": [
        true,
        "check-property",
        "check-constructor",
        "check-method"
      ],
      "framework-call-subject-next": true,
      "variable-name": [
        true,
        "check-format",
        "allow-leading-underscore",
        "ban-keywords"
      ]
    },
    "rulesDirectory": [
      "codelyzer",
      "@tools/tslint-rules"
    ]
  }

.editorconfig (if any)

    "tsImportSorter.configuration.maxBindingNamesPerLine": 0,
    "tsImportSorter.configuration.maxDefaultAndBindingNamesPerLine": 0,
    "tsImportSorter.configuration.maxNamesPerWrappedLine": 0,
    "tsImportSorter.configuration.configurationFileName": "C:\\Users\\XXXX\\AppData\\Roaming\\Code\\User\\import-sorter.json",
    "tsImportSorter.configuration.exclude": [
        "node_modules",
        "polyfills.ts",
        "polyfills.browser.ts"
    ]
{
  "maxLineLength": 120,
  "quoteMark": "simple",
  "tabSize": 4,
  "insertFinalNewline": false,
  "groupRules": [ 
      {
        "regex": "^@angular/",
        "level": 10
      },  
      {
        "regex": "rxjs",
        "level": 11
      },
      {
        "regex": "^(?!(src|projects|lib)/)[a-z]",
        "level": 13
      },
      {
        "regex": "^@framework/",
        "level": 14
      },
      {
        "regex": "^[@]",
        "level": 15
      },
      {
        "regex": "^(src|lib|projects)/",
        "level": 20
      },
      {
        "regex": "^[.][.]",
        "level": 30
      },
      {
        "regex": "^(?!.*routing)[.]/",
        "level": 40
      },
      {
        "regex": "^[.]/",
        "level": 50
      }
   ]
}

Installed VS Code extensions

cssho.vscode-svgviewer
deerawan.vscode-hasher
dozerg.tsimportsorter 
eamodio.gitlens
EditorConfig.EditorConfig
file-icons.file-icons
herrmannplatz.npm-dependency-links
jamesmaj.easy-icons
johnstoncode.svn-scm
LaurentTreguier.vscode-simple-icons
michelemelluso.gitignore
mike-co.import-sorter
ms-azuretools.vscode-docker
MS-CEINTL.vscode-language-pack-fr
ms-vscode-remote.remote-wsl
ms-vscode.vscode-typescript-tslint-plugin
msjsdiag.debugger-for-chrome
nepaul.editorconfiggenerator
obrejla.netbeans-light-theme
redhat.java
sasa.vscode-sass-format
Telerik.nativescript
traBpUkciP.vscode-npm-scripts
Tyriar.terminal-tabs
VisualStudioExptTeam.vscodeintellicode
vscjava.vscode-java-debug
vscjava.vscode-java-dependency
vscjava.vscode-java-pack
vscjava.vscode-java-test
vscjava.vscode-maven
xyz.local-history
daidodo commented 3 years ago

@Zefling

Thanks for your feedback!

Could you provide the code snippet or a link to the source file that causing the issue? In my end (MacBook Pro) it takes ~100ms to format a 150-line TS file with 30 lines of imports.

You should be able to find out the exact time used when formatting a file in the Output channel for this extension:

1

Hope that helps!

Zefling commented 3 years ago

I have this problem a workspace with a lot of projects. If I remove this extension, the slowdowns disappear. Sort2 On a new workspace, not problem. It's strange.

daidodo commented 3 years ago

Could you setup a shared workspace so I can reproduce the issue?

Zefling commented 3 years ago

The workspace with project isn't possible because it's not a open source projects. :(

daidodo commented 3 years ago
  1. Is it only you having the issue or others too?
  2. Have you tried to uninstall this extension and reinstall?
  3. Could you reboot your computer or try on another one?

Looks like the first log (after resolving your configuration) took a long time to show. That could be because:

Reinstalling the extension might fix A and C if it's an env setup issue. If not, it's most likely an I/O issue because this extension reads config from various sources, e.g package.json, tsconfig.json, Prettier's config, EditorConfig's config, etc. Reboot your computer or try on another one to see if it's a lock/disk issue.

Edit: I released a new version (3.1.0) with improved logs. It will output a log before configuration resolution so may help to justify A and C without reinstalling.

Zefling commented 3 years ago

With the new log:

[2020-11-30T10:08:56.442] [INFO] formatDocument - Start formatting fileName: c:\xxxxxx\xxxx.ts
[2020-11-30T10:09:04.188] [INFO] formatDocument - Resolved config: {

I find this:

[2020-11-30 10:11:45.885] [renderer3] [warning] UNRESPONSIVE extension host, 'dozerg.tsimportsorter' took 100% of 3620.362ms, saved PROFILE here: 'c:\Users\CVEYSS~1\AppData\Local\Temp\exthost-a5edd4.cpuprofile' [{"id":"dozerg.tsimportsorter","total":3610140,"percentage":100},{"id":"eamodio.gitlens","total":235,"percentage":0},{"id":"gc","total":6140,"percentage":0},{"id":"self","total":975,"percentage":0},{"id":"vscode.merge-conflict","total":769,"percentage":0},{"id":"vscode.typescript-language-features","total":1771,"percentage":0}]
daidodo commented 3 years ago

@Zefling Thanks for your helpful logs!

I've released a new revision (3.1.1) with more logs into config resolution. Could you try and share your new logs here?

daidodo commented 3 years ago

Hi @Zefling,

From v4.1.0, you can switch on/off Debug Mode in User Settings. Maybe it can help you find useful logs if the issue appears again.

Thanks!

Zefling commented 3 years ago

With the last version :

[2020-12-16T17:18:30.214] [INFO] vscode.resolveConfig - Start resolving configs for fileName: c:\<path>\<file>.component.ts, languageId: typescript
[2020-12-16T17:18:30.217] [DEBUG] config.loadVscConfig - Finish loading VSC config
[2020-12-16T17:18:30.217] [DEBUG] config.loadImportSorterConfig - Load Prettier/EditorConfig config.
[2020-12-16T17:18:30.218] [INFO] config.loadPretConfig - Prettier API version:  2.2.1
[2020-12-16T17:18:30.239] [DEBUG] config.loadImportSorterConfig - Load import-sorter config from C:\Users\XXXX\AppData\Roaming\Code\User\import-sorter.json
[2020-12-16T17:18:30.240] [DEBUG] config.loadImportSorterConfig - Load package.json config.
[2020-12-16T17:18:30.242] [DEBUG] config.loadESLintConfig - Start loading ESLint config for filePath: c:\<path>\<file>.component.ts
[2020-12-16T17:18:30.242] [INFO] config.loadESLintConfig - ESLint API version: 7.15.0
[2020-12-16T17:18:30.263] [WARN] config.loadESLintConfig - Failed loading ESLint config: No ESLint configuration found in c:\<path>.
[2020-12-16T17:18:30.263] [DEBUG] config.loadTsConfig - Find TS config for fileName: c:\<path>\<file>.component.ts
[2020-12-16T17:18:30.264] [DEBUG] config.loadTsConfig - Load TS config for fileName: c:\<path>\<file>.component.ts
[2020-12-16T17:18:38.381] [DEBUG] vscode.resolveConfig - Finish resolving configs.
[2020-12-16T17:18:38.382] [DEBUG] formatDocument - Start formatting fileName: c:\<path>\<file>.component.ts
[2020-12-16T17:18:38.382] [INFO] parser.formatSource - config: {
daidodo commented 3 years ago

Thanks for your logs, @Zefling !

Looks like the issue is tsconfig.json loading. Currently, I'm not sure about the root cause as your config worked fine in my laptop. But I'll keep watching it.

If you find more clues, please let me know and I'll appreciate it!

JohnLouderback commented 3 years ago

For what it's worth, I also have a codebase that experiences this slowness.

daidodo commented 3 years ago

@JohnLouderback Thanks for the feedback!

Is it possible that I can access the codebase? Or can you make a demo project to reproduce the issue?

daidodo commented 3 years ago

@Zefling and @JohnLouderback - Are you still having the performance issue? There is another issue that might be related and I've fixed it, so I'll close this one. Feel free to re-open it if you have more questions. Thanks!

Zefling commented 3 years ago

Sorry, I'm no longer working on the problematic project. I haven't noticed the problem on other projects. It is possible that it is a problem of workspace.