fix: speed up "fast" linters #4653
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, there are 2 problems:
typecheckusesLoadModeTypesInfoandWithLoadForGoAnalysis.So the load mode of the linter config for the
metalinteris alwaysLoadModeTypesInfoand neverLoadModeSyntax.metalinterhas a hardcoded call toWithLoadForGoAnalysis, then the types are always loaded.As a consequence, the "fast" linters (like
lll,gofmt,misspell, etc.) are slower than expected when either they are running alone or only "fast" linters are run.This PR changes the config linter load mode of
typechecktoLoadModeNoneand removesWithLoadForGoAnalysisfor this fake linter.The
metalintergoanalysis load mode is computed based on linters.typecheckdoesn't need an explicit load mode because it is never run alone, then at the end, the load mode will depend on the load mode of the real linters.Same thing for the goanalysis load mode.
FYI, there are 2 load modes:
LoadModeTypesInfo,LoadModeSyntax, etc.)WithLoadForGoAnalysis,WithLoadFiles)They are used for different purposes.
Based on local tests (verbose mode), the performances are improved (~50%).
On golangci-lint code
Current version:
golangci-lint cache clean; golangci-lint run --enable-only misspell --enable-only lll -vWith the PR:
golangci-lint cache clean; ./golangci-lint run --enable-only misspell --enable-only lll -vOn Traefik code
Current version:
golangci-lint cache clean; golangci-lint run --enable-only gofmt --enable-only misspell -vCurrent version:
golangci-lint cache clean; ./golangci-lint run --enable-only gofmt --enable-only misspell -vFixes #2914
Fixes #4639