Skip to content

Commit 9a94079

Browse files
fix: speed up gopls lint with parallel processing
The gopls check was slow (~3.5 minutes) because it processed all ~2800 Go source files sequentially. This change: 1. Installs gopls once instead of using 'go run' each time 2. Uses xargs with parallel execution (-P nproc) to process files in batches of 100 across all available CPU cores This reduces the lint time from ~3.5 minutes to ~1 minute (about 68% faster). Closes #121 Co-Authored-By: Greg Slepak <contact@taoeffect.com>
1 parent b589b12 commit 9a94079

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tools/lint-go-gopls.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,18 @@ IGNORE_PATTERNS=(
77
"is deprecated" # TODO: fix these
88
)
99

10+
# Install gopls if not already installed, then use the installed binary for
11+
# faster execution. Using 'go run' each time adds overhead.
12+
"$GO" install "$GOPLS_PACKAGE" 2>/dev/null
13+
GOPLS_BIN=$("$GO" env GOPATH)/bin/gopls
14+
1015
# lint all go files with 'gopls check' and look for lines starting with the
1116
# current absolute path, indicating a error was found. This is necessary
1217
# because the tool does not set non-zero exit code when errors are found.
1318
# ref: https://github.com/golang/go/issues/67078
14-
ERROR_LINES=$("$GO" run "$GOPLS_PACKAGE" check -severity=warning "$@" 2>/dev/null | grep -E "^$PWD" | grep -vFf <(printf '%s\n' "${IGNORE_PATTERNS[@]}"));
19+
# Use xargs with parallel execution (-P) to speed up checking many files.
20+
# Each batch of 100 files is processed in parallel across available cores.
21+
ERROR_LINES=$(printf '%s\n' "$@" | xargs -P "$(nproc)" -n 100 "$GOPLS_BIN" check -severity=warning 2>/dev/null | grep -E "^$PWD" | grep -vFf <(printf '%s\n' "${IGNORE_PATTERNS[@]}"));
1522
NUM_ERRORS=$(echo -n "$ERROR_LINES" | wc -l)
1623

1724
if [ "$NUM_ERRORS" -eq "0" ]; then

0 commit comments

Comments
 (0)