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

format imports is slow #89

Open tjx666 opened 1 year ago

tjx666 commented 1 year ago

Describe the bug

This happen in a large monorepo project.

[2022-12-31T17:17:20.334] [INFO] vscode.resolveConfig - Resolving config for fileName: /Users/yutengjing/code/xxx/packages/yyy/src/components/attribute-panel/element-panel/chart/utils/chart-category.ts languageId: typescript
[2022-12-31T17:17:20.413] [INFO] format-imports.extractOptions - Found ESLint rule import/newline-after-import: { count: 1 }
[2022-12-31T17:17:20.414] [INFO] format-imports.formatSource - Formatting /Users/yutengjing/code/xxx/packages/yyy/src/components/attribute-panel/element-panel/chart/utils/chart-category.ts with enhanced config: {
  configurationFileName: 'import-sorter.json',
  autoFormat: 'off',
  formatExports: true,
  exclude: [ 'node_modules' ],
  excludeGlob: [],
  sortImportsBy: 'paths',
  nodeProtocol: 'always',
  groupRules: [
    [ [Object], '^[@][^/]', {} ],
    { flags: 'named', regex: '^[.]' },
    [ [Object], [Object] ]
  ],
  sortRules: { paths: [ '_', 'aA' ], names: [ '_', 'aA' ] },
  keepUnused: [ '.*' ],
  emptyLinesBetweenGroups: 1,
  emptyLinesAfterAllImports: 1,
  removeLastSlashInPath: false,
  removeLastIndexInPath: false,
  wrappingStyle: 'prettier',
  development: { enableDebug: false },
  insertFinalNewline: true,
  eol: 'LF',
  force: false,
  maxLineLength: 100,
  tabType: 'space',
  tabSize: 4,
  hasSemicolon: true,
  quoteMark: 'single',
  trailingComma: 'multiLine',
  bracketSpacing: true,
  '$schema': './node_modules/format-imports/schemas/import-sorter.schema.json'
}
[2022-12-31T17:17:20.436] [INFO] vscode.formatDocument - Finished format
[2022-12-31T17:17:20.508] [INFO] vscode.resolveConfig - Resolving config for fileName: /Users/yutengjing/code/xxx/packages/yyy/src/components/attribute-panel/element-panel/chart/utils/chart-category.ts languageId: typescript
[2022-12-31T17:17:20.508] [INFO] vscode.formatDocument - Auto format is off

Expected behavior

should be faster, my ideal speed is to <= 50ms

Actual behavior

170ms ~ 200ms, however the prettier format can control under 50~100ms

Screenshots

https://user-images.githubusercontent.com/41773861/210131817-ee3f630d-6f0f-4a27-969d-be37a13a3bed.mov

OS (please complete the following information):

System: OS: macOS 13.1 CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz Memory: 241.86 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh

VS Code (please complete the following information):

Version: 1.74.2 (Universal)
Commit: e8a3071ea4344d9d48ef8a4df2c097372b0c5161
Date: 2022-12-20T10:26:09.430Z
Electron: 19.1.8
Chromium: 102.0.5005.167
Node.js: 16.14.2
V8: 10.2.154.15-electron.0
OS: Darwin x64 22.2.0
Sandboxed: No

package.json (please remove any sensitive info)

tsconfig.json (if any)

.prettierrc/.prettierrc.js/prettier.config.js/.prettierrc.toml (if any) filename:

.editorconfig (if any)

Installed VS Code extensions [Execute $ code --list-extensions in terminal to get the list. How to run VS Code from terminal in MacOS]

aaron-bond.better-comments
adam-bender.commit-message-editor
Adobe.extendscript-debug
alefragnani.read-only-indicator
amodio.tsl-problem-matcher
andersonbruceb.json-in-html
antfu.file-nesting
arichy.vscode-ast-explorer
berublan.vscode-log-viewer
bierner.color-info
bierner.emojisense
bierner.gif-player
bierner.jsdoc-markdown-highlighting
bierner.markdown-preview-github-styles
bodil.file-browser
brunnerh.file-properties-viewer
caiqichang.vscode-translation
chekweitan.compare-view
chrisdias.vscode-opennewinstance
chriskirknielsen.visubezier
chunsen.bracket-select
CodeQue.codeque
codezombiech.gitignore
colder.source-map-visualization
connor4312.esbuild-problem-matchers
cschleiden.vscode-github-actions
DavidAnson.vscode-markdownlint
dbaeumer.vscode-eslint
devonray.snippet
donjayamanne.githistory
dozerg.tsimportsorter
dracula-theme.theme-dracula
dtsvet.vscode-wasm
dzhavat.css-flexbox-cheatsheet
dzhavat.css-initial-value
eamodio.gitlens
ecmel.vscode-html-css
EditorConfig.EditorConfig
esbenp.prettier-vscode
formulahendry.code-runner
foxundermoon.shell-format
Gruntfuggly.todo-tree
haberdashPI.vscode-select-by-indent
idered.npm
infarkt.css-to-jss
ionutvmi.path-autocomplete
IronGeek.vscode-env
jakearl.search-editor-apply-changes
jjaakko.markdown-kbd
jock.svg
karenpommeroy.batch-rename
kisstkondoros.vscode-gutter-preview
L13RARY.l13-diff
liulongbin1314.escook-translate
medo64.render-crlf
meganrogge.template-string-converter
mhutchie.git-graph
mkxml.vscode-filesize
mrmlnc.vscode-scss
ms-vscode.hexeditor
ms-vscode.live-server
ms-vscode.vscode-typescript-next
octref.vetur
Orta.vscode-twoslash-queries
pomber.git-file-history
pomdtr.excalidraw-editor
pucelle.vscode-css-navigation
qcz.text-power-tools
redhat.vscode-xml
redhat.vscode-yaml
robole.snippets-ranger
rust-lang.rust-analyzer
saber2pr.ts-ast-viewer
sleistner.vscode-fileutils
streetsidesoftware.code-spell-checker
stylelint.vscode-stylelint
thzt.vscode-ast
trietho.file-size-explorer
uctakeoff.vscode-counter
ultram4rine.vscode-choosealicense
VisualStudioExptTeam.vscodeintellicode
vscode-icons-team.vscode-icons
Vue.volar
Vue.vscode-typescript-vue-plugin
vunguyentuan.vscode-css-variables
YuTengjing.adobe-extension-devtools
YuTengjing.modify-file-warning
YuTengjing.neo-vue-helper
YuTengjing.open-in-external-app
YuTengjing.scripting-listener
YuTengjing.view-github-repository
YuTengjing.vscode-archive
YuTengjing.vscode-colorize-plus
YuTengjing.vscode-fe-helper
YuTengjing.vscode-neo-file-utils
YuTengjing.vscode-versionlens-plus
YuTengjing.ytj-snippets
yzhang.markdown-all-in-one
zenghongtu.vscode-asciiflow2
zhaouv.vscode-markdown-draw
zhuangtongfa.material-theme
zyrong.node-modules
tjx666 commented 1 year ago

Because I add it to codeActions, I can see a big delay after I cmd + s:

{
    "editor.codeActionsOnSave": {
        "source.addMissingImports": true,
        "source.fixAll.eslint": true,
        "source.fixAll.stylelint": true,
        "source.fixAll.markdownlint": true,
        "source.organizeImports.sortImports": true
    },
}
tjx666 commented 1 year ago

I try to analyze why slow from extension log:

  1. format-imports seems try to get eslint rules info? I tiink it would be better to provide option instead of get eslint info. Like prettier, prettier hope user close all rules that should be handled by prettier.
  2. After Finish format, why resolve config again?