https://github.com/khordadi updated https://github.com/llvm/llvm-project/pull/243430
>From 0432b395bca971447bb11bf8cf3421134ce2de00 Mon Sep 17 00:00:00 2001 From: Amir Khordadi <[email protected]> Date: Tue, 17 Nov 2026 06:16:30 -0500 Subject: [PATCH 1/2] [clang-tidy] Start the largest files first in run-clang-tidy run-clang-tidy keeps the files from the compilation database in a set, so it starts them in an arbitrary order that changes from run to run. When a few files take much longer than the rest, a run waits on whichever of them happens to start last. Start the files in decreasing order of size instead, breaking ties by path. Size is a cheap proxy for how long clang-tidy takes on a file, and starting the longest jobs first keeps them off the end of the run. Files that cannot be read sort last, and clang-tidy reports them as before. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- .../clang-tidy/tool/run-clang-tidy.py | 7 ++++++- clang-tools-extra/docs/ReleaseNotes.md | 3 +++ .../infrastructure/run-clang-tidy-file-order.cpp | 14 ++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy-file-order.cpp diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py index f827ef492f01ce..a4dadc5811973a 100755 --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -707,6 +707,11 @@ async def main() -> None: returncode = 0 semaphore = asyncio.Semaphore(max_task) + # Start the largest files first: they tend to take the longest, and the + # run cannot finish before the last of them does. + largest_first = sorted( + files, key=lambda f: (-os.path.getsize(f) if os.path.isfile(f) else 0, f) + ) tasks = [ asyncio.create_task( run_with_semaphore( @@ -720,7 +725,7 @@ async def main() -> None: profile_dir, ) ) - for f in files + for f in largest_first ] try: diff --git a/clang-tools-extra/docs/ReleaseNotes.md b/clang-tools-extra/docs/ReleaseNotes.md index 2566c24544d706..e0a8b2f9b7fe32 100644 --- a/clang-tools-extra/docs/ReleaseNotes.md +++ b/clang-tools-extra/docs/ReleaseNotes.md @@ -143,6 +143,9 @@ infrastructure are described first, followed by tool-specific sections. `ImplementationFileExtensions` contains an invalid entry, such as one with a leading dot. The invalid option is now reported as a warning. +- Improved {program}`run-clang-tidy.py` to start the largest files first, which + shortens runs where a few slow files would otherwise start last. + #### New checks - New {doc}`bugprone-macro-condition diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy-file-order.cpp b/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy-file-order.cpp new file mode 100644 index 00000000000000..acde20221a9d3b --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/infrastructure/run-clang-tidy-file-order.cpp @@ -0,0 +1,14 @@ +// RUN: rm -rf %t +// RUN: mkdir %t +// RUN: echo "[{\"directory\":\".\",\"command\":\"clang++ -c %/t/a-small.cpp\",\"file\":\"%/t/a-small.cpp\"},{\"directory\":\".\",\"command\":\"clang++ -c %/t/b-large.cpp\",\"file\":\"%/t/b-large.cpp\"},{\"directory\":\".\",\"command\":\"clang++ -c %/t/c-small.cpp\",\"file\":\"%/t/c-small.cpp\"}]" | sed -e 's/\\/\\\\/g' > %t/compile_commands.json +// RUN: echo "Checks: '-*,misc-unused-using-decls'" > %t/.clang-tidy +// RUN: echo "int a;" > %t/a-small.cpp +// RUN: cp "%s" "%t/b-large.cpp" +// RUN: echo "int c;" > %t/c-small.cpp +// RUN: cd "%t" +// RUN: %run_clang_tidy -j 1 2>&1 | FileCheck %s + +// Files start largest first, and files of the same size in path order. +// CHECK: [1/3]{{.*}}b-large.cpp +// CHECK: [2/3]{{.*}}a-small.cpp +// CHECK: [3/3]{{.*}}c-small.cpp >From 31de1a7f6e35712e47845536ea5f383875467d0d Mon Sep 17 00:00:00 2001 From: Amir Khordadi <[email protected]> Date: Wed, 18 Nov 2026 05:47:06 -0500 Subject: [PATCH 2/2] Sort the files where they are filtered Co-Authored-By: Claude Opus 5.5 <[email protected]> --- .../clang-tidy/tool/run-clang-tidy.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py index a4dadc5811973a..54eba969624d04 100755 --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -697,7 +697,12 @@ async def main() -> None: # Build up a big regexy filter from all command line arguments. file_name_re = re.compile("|".join(args.files)) - files = {f for f in files if file_name_re.search(f)} + # Start the largest files first: they tend to take the longest, and the + # run cannot finish before the last of them does. + files = sorted( + (f for f in files if file_name_re.search(f)), + key=lambda f: (-os.path.getsize(f) if os.path.isfile(f) else 0, f), + ) if not args.hide_progress: print( @@ -707,11 +712,6 @@ async def main() -> None: returncode = 0 semaphore = asyncio.Semaphore(max_task) - # Start the largest files first: they tend to take the longest, and the - # run cannot finish before the last of them does. - largest_first = sorted( - files, key=lambda f: (-os.path.getsize(f) if os.path.isfile(f) else 0, f) - ) tasks = [ asyncio.create_task( run_with_semaphore( @@ -725,7 +725,7 @@ async def main() -> None: profile_dir, ) ) - for f in largest_first + for f in files ] try: _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
