Skip to content

Commit 6089456

Browse files
committed
Speed up ./tools/format with parallelism
Run multiple instances of clang-format to maximize CPU utilization. This speeds up the ./tools/format script from 0.78 seconds to 0.26 seconds on my AMD Ryzen 5950X CPU (32 threads).
1 parent 37a7e6d commit 6089456

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

tools/format

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ set -u
1010
cd "$(dirname "${0}")/.."
1111
source tools/files.sh
1212

13-
find_non_vendor_files | matching '\.(c|cpp|h)$' | xargs clang-format -i
13+
parallelism=$(nproc 2>/dev/null)
14+
if [[ -z "${parallelism}" ]]; then
15+
parallelism=3
16+
fi
17+
18+
files_to_parse=($(find_non_vendor_files | matching '\.(c|cpp|h)$'))
19+
chunk_size=$(((${#files_to_parse[@]} + ${parallelism} - 1) / ${parallelism}))
20+
21+
printf '%s\n' "${files_to_parse[@]}" \
22+
| xargs "-P${parallelism}" "-n${chunk_size}" clang-format -i
1423

1524
# quick-lint-js finds bugs in JavaScript programs.
1625
# Copyright (C) 2020 Matthew Glazar

0 commit comments

Comments
 (0)