From 1ed564fed5512502677bde195fbd683b2db5dd46 Mon Sep 17 00:00:00 2001 From: Hugo Date: Sun, 15 Nov 2026 05:34:10 +0100 Subject: [PATCH 1/3] fix(app): load the shared modules one at a time, on the calling thread With cross-TU summaries, every input is loaded before the analysis. With --jobs above 1, each input was loaded on a worker thread, yet its compilation runs under gCompileInvokeMutex: a worker only parsed its bitcode in parallel. glibc gives each of those workers an arena of its own, and the memory a compilation frees stays in that arena after the worker ends, for the rest of the run. On the self-analysis's chunks of 14 files, an analyzer at --jobs=32 held 1.6 to 2.4 GiB more after loading than at --jobs=1, almost all of it free memory kept by the 14 worker arenas, and its loading was no faster. Load the inputs one after the other on the calling thread, whatever --jobs. The cross-TU summaries still run on --jobs workers. The README no longer says that --jobs parallelizes the loading of cross-TU runs. --- README.md | 4 ++-- src/app/AnalyzerApp.cpp | 17 ++++++----------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 420cbbd..941759e 100644 --- a/README.md +++ b/README.md @@ -295,7 +295,7 @@ To generate `compile_commands.json` with CMake, configure with If analysis feels slow, `--compdb-fast` disables heavy flags (optimizations, sanitizers, profiling) while keeping include paths and macros. -For multi-file runs, `--jobs=` parallelizes input loading; with cross-TU enabled it also parallelizes summary construction. +For multi-file runs, `--jobs=` parallelizes input loading and analysis; with cross-TU enabled, inputs are loaded one at a time (their compilations are serialized) and it parallelizes summary construction. `--compile-ir-cache-dir=` reuses compiled LLVM IR for unchanged translation units based on source/dependency stamps, which reduces repeated C/C++ frontend cost across runs. IR that another compiler produced (another coretrace-compiler revision or LLVM version) is compiled again. @@ -574,7 +574,7 @@ Cross-TU summary behavior: - `--no-resource-cross-tu` forces local-only (single-file) resource reasoning. - `--resource-summary-cache-dir=` controls where per-module summary cache files are stored. - `--resource-summary-cache-memory-only` disables filesystem cache writes and uses an in-process cache only. -- `--jobs=` parallelizes module loading/compilation and per-module summary extraction during each fixpoint iteration. +- `--jobs=` parallelizes per-module summary extraction during each fixpoint iteration; modules are loaded one at a time. - The CLI prints an explicit status line to `stderr` to indicate whether resource inter-procedural analysis is enabled or unavailable/disabled (with reason). - If a local release depends on an unmodeled/external callee and no summary is available, the tool diff --git a/src/app/AnalyzerApp.cpp b/src/app/AnalyzerApp.cpp index 54f3e66..500e329 100644 --- a/src/app/AnalyzerApp.cpp +++ b/src/app/AnalyzerApp.cpp @@ -957,17 +957,12 @@ static AppStatus analyzeWithSharedModuleLoading(const std::vector& loadSucceeded[index] = 1; }; - const unsigned loadJobs = resolveConfiguredJobs(cfg); - if (loadJobs <= 1 || inputFilenames.size() <= 1) - { - for (std::size_t index = 0; index < inputFilenames.size(); ++index) - loadSingleModule(index); - } - else - { - runParallelWork(inputFilenames.size(), loadJobs, - [&](std::size_t index) { loadSingleModule(index); }); - } + // One input after the other, on this thread, whatever --jobs. The compilations are serialized + // (InputPipeline.cpp): a loading worker would only parse its bitcode in parallel, while glibc + // would give it an arena of its own and keep there the memory its compilation freed, about one + // compilation per worker for the rest of the run. The cross-TU summaries below still use --jobs. + for (std::size_t index = 0; index < inputFilenames.size(); ++index) + loadSingleModule(index); std::vector orderedLoadedModules; orderedLoadedModules.reserve(inputFilenames.size()); From 4ae52d7d0593d710ddab294df16a463cf542e054 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 16 Nov 2026 02:40:18 +0100 Subject: [PATCH 2/3] docs(readme): say that --jobs parallelizes only the summaries of multi-file runs A run of more than one input always takes the shared loading, as it builds the global read-before-write summaries, and it analyzes its modules one after the other. With the previous commit, it also loads them one after the other: --jobs only parallelizes the construction of the cross-TU summaries. The sentence the previous commit wrote said that --jobs parallelized loading and analysis in multi-file runs without cross-TU. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 941759e..26d914e 100644 --- a/README.md +++ b/README.md @@ -295,7 +295,7 @@ To generate `compile_commands.json` with CMake, configure with If analysis feels slow, `--compdb-fast` disables heavy flags (optimizations, sanitizers, profiling) while keeping include paths and macros. -For multi-file runs, `--jobs=` parallelizes input loading and analysis; with cross-TU enabled, inputs are loaded one at a time (their compilations are serialized) and it parallelizes summary construction. +For multi-file runs, `--jobs=` parallelizes the construction of cross-TU summaries; the inputs are loaded one at a time, as their compilations are serialized. `--compile-ir-cache-dir=` reuses compiled LLVM IR for unchanged translation units based on source/dependency stamps, which reduces repeated C/C++ frontend cost across runs. IR that another compiler produced (another coretrace-compiler revision or LLVM version) is compiled again. From e60a10e9b22b13a29f562db92c5c6b3435de0e06 Mon Sep 17 00:00:00 2001 From: Hugo Date: Mon, 16 Nov 2026 03:53:46 +0100 Subject: [PATCH 3/3] docs: describe --jobs as it works in --help and the README's option list --help and the README's list of options still said that --jobs parallelizes the loading and the analysis of multi-file runs, with a default of 1. A run of more than one input loads and analyzes its modules one after the other, and --jobs only parallelizes the construction of its cross-TU summaries; it defaults to auto, the number of hardware threads (resolveConfiguredJobs). The sentence the previous commit wrote also gave the serialized compilations as the reason for loading one input at a time, which does not hold for an input already in LLVM IR or found in the compile IR cache: it now only says what happens. --- README.md | 4 ++-- main.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 26d914e..249ebf7 100644 --- a/README.md +++ b/README.md @@ -252,7 +252,7 @@ Ready-to-adapt workflow examples: --compdb= alias for --compile-commands --compdb-fast drops heavy build flags for faster analysis --include-compdb-deps includes `_deps` entries when inputs are auto-discovered from compile_commands.json ---jobs= parallel jobs for multi-file loading/analysis and cross-TU resource summary build (default: 1) +--jobs= parallel jobs for the cross-TU summaries of multi-file runs (default: auto) --escape-model= loads external noescape rules for stack pointer escape analysis (`noescape_arg`) --buffer-model= loads external buffer write rules for copy/string overflow checks (`bounded_write`/`unbounded_write`) --resource-model= loads external acquire/release rules for generic resource lifetime checks @@ -295,7 +295,7 @@ To generate `compile_commands.json` with CMake, configure with If analysis feels slow, `--compdb-fast` disables heavy flags (optimizations, sanitizers, profiling) while keeping include paths and macros. -For multi-file runs, `--jobs=` parallelizes the construction of cross-TU summaries; the inputs are loaded one at a time, as their compilations are serialized. +For multi-file runs, `--jobs=` parallelizes the construction of cross-TU summaries; the inputs are loaded one at a time. `--compile-ir-cache-dir=` reuses compiled LLVM IR for unchanged translation units based on source/dependency stamps, which reduces repeated C/C++ frontend cost across runs. IR that another compiler produced (another coretrace-compiler revision or LLVM version) is compiled again. diff --git a/main.cpp b/main.cpp index 5ad7ec0..80bd486 100644 --- a/main.cpp +++ b/main.cpp @@ -51,8 +51,8 @@ static void printHelp() << " --compdb-fast Speed up compdb builds (drops heavy flags)\n" << " --include-compdb-deps Include _deps entries when auto-discovering files from " "compile_commands.json\n" - << " --jobs= Parallel jobs for multi-file loading/analysis and cross-TU " - "summary build (default: 1)\n" + << " --jobs= Parallel jobs for the cross-TU summaries of multi-file runs " + "(default: auto)\n" << " If no input files are provided, supported files are loaded\n" << " from compile_commands.json automatically.\n" << " --timing Print compilation/analysis timing to stderr\n"