Repository navigation
perf(input): compile sources in parallel, each in its directory - #272
Draft
SizzleUnrlsd wants to merge 17 commits into
Draft
SizzleUnrlsd wants to merge 17 commits into
SizzleUnrlsd wants to merge 17 commits into
Conversation
…rectory The pinned commit, from CoreTrace/coretrace-compiler#262, gives each compilation a file system of its own, whose working directory -working-directory moves while the process's stays. The analyzer does not use it yet: it still moves the process around each compilation, under its lock. Refs #271
Every compilation held one global lock and moved the whole process to its compile command's directory: the --jobs threads compiled one source at a time. coretrace-compiler now gives each compilation the directory of its -working-directory without moving the process: the analyzer passes the directory that way, and compilations share the lock. Some compilations still hold it alone, since they change state that the whole process shares: those with an option that Clang applies to LLVM's state (-mllvm, -mdebug-pass, -mlimit-float-precision, -ftime-report), and those with -fno-integrated-cc1, whose jobs run as programs, for which coretrace-compiler moves the process. A compile command whose directory does not exist still fails the analysis: coretrace-compiler reports a directory it cannot enter, but compiles to memory all the same, so the analyzer checks the directory itself, with the message it gave before. Refs #271
The newer commit of CoreTrace/coretrace-compiler#262 also writes the fragment of -MJ, the statistics of -save-stats, the graph of -dependency-dot and the module cache in the directory of -working-directory, as the analyzer did when it moved the process there. Refs #271
This was referenced Nov 14, 2026
With -fno-integrated-cc1, the jobs of a compile command run as programs: coretrace-compiler moves the process to the command's directory and leaves it there. The scoped change of directory that this branch removed used to bring the process back. After a load of such a source, the process stayed in the command's directory, where a relative source without a compile command was no longer found. A compilation that holds the lock alone now puts the process back before it releases the lock. The compilations that share the lock do not move the process, and still run at once. Refs #271
A source whose compile command passes -fno-integrated-cc1 is loaded, then a relative source without a compile command. Before the fix, the process was left in the command's directory and the second load failed. Refs #271
This was referenced Nov 16, 2026
SizzleUnrlsd
added a commit
that referenced
this pull request
Nov 17, 2026
The table of each phase was kept for the first repetition only: the phases after loading can now be compared over every repetition. Refs #272
SizzleUnrlsd
added a commit
that referenced
this pull request
Nov 21, 2026
The third run told the compiler's update from #274 at one job. This one tells whether the rework of #272 needs #274: three analyzers that build coretrace-compiler v0.13.0, measured in turn at 1, 2 and 4 jobs. - main: main with the compiler of #274 and nothing else of it. - 272: main merged with #272, with the rework's loading on at most four workers and its release of freed memory. The bitcode is read back. - 272-274: the same with #274 merged too. The three trees are laid out on the runner without a commit, and compared with the ones computed before the run. Refs #272
README.md had the one conflict, on the sentence that describes --jobs: main's stays (#285). After this merge the inputs still load one at a time, as on main, since src/app/AnalyzerApp.cpp is main's.
The branch pinned a commit of CoreTrace/coretrace-compiler#262 while that pull request was open. v0.13.0 (e213053) is the release that holds it. Refs #271
…--jobs=N Since #285 the inputs of a multi-file run load one after the other: their compilations ran under one lock, so a loading worker only parsed its bitcode in parallel. On this branch the compilations share that lock, and the loading workers compile at once. Each compilation in progress holds its own memory, so the loading takes fewer workers than --jobs allows: two when the count is left to the machine (the default, or --jobs=auto), and min(N, 4) with --jobs=N. The other phases use --jobs as before. Refs #271
Under glibc, the memory a compilation frees stays in the arena of the thread that ran it, for the rest of the run (#285). Once the inputs are loaded, malloc_trim gives it back. The call is compiled under glibc only. On the Linux measure of this loading (run 44956551908, this repository's 53 C++ sources, medians of 3 runs), the analyzer holds 627 MiB of anonymous memory after loading at one job, where the loading is otherwise main's, against 714 MiB for main with the same compiler; 646 and 641 MiB at 2 and 4 jobs, against 747 and 748 MiB. Refs #271
Twelve C files are loaded without a cache, with --timing. The check counts the inputs whose load has started and is not done, line after line of the log: two at once without --jobs and with --jobs=auto, on a machine of two processors or more, and min(N, 4) with --jobs=N, for 1, 2, 3, 4 and 8. Refs #271
…cache Twelve C files are analyzed one at a time without a cache, then at once from an empty compile IR cache, which their loads fill together, then from that cache, without --jobs and with --jobs=4. The four runs must give the diagnostics and the functions of the first, the runs on the filled cache must read every input from it, and the others none. Refs #271
The loading is bounded where a multi-file run loads all its inputs before the analysis, which every multi-file run does today. The check adds a run with --no-resource-cross-tu and --no-uninitialized-cross-tu at --jobs=8, to fail the day such a run loads its inputs another way. Refs #271
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Every compilation held
gCompileInvokeMutexand moved the whole process to its compile command's directory, so the sources of a run compiled one at a time (#271). coretrace-compiler gives each compilation the directory of its-working-directorywithout moving the process (CoreTrace/coretrace-compiler#262, released in v0.13.0). The analyzer passes each compile command's directory that way, compilations share the lock, and the inputs of a multi-file run load at once, on a bounded number of workers.Closes #271
What
--jobsdoes--jobsautoNmin(N, 4)N, as on mainOn main the inputs load one at a time, whatever
--jobs(#285). Each compilation in progress holds its own memory, which is what the bound limits. A run of one input is not concerned.Change
README.mdhad the one conflict, on the sentence about--jobs.build(deps): update coretrace-compiler to v0.13.0: the release that holds feat(compilerlib): give each compilation a working directory of its own coretrace-compiler#262. The branch pinned a commit of that pull request while it was open.perf(input): compile sources in parallel, each in its directory, as reviewed at bbaab08:-working-directory <directory>is prepended to the compile command's arguments;ScopedCurrentPath, which moved the process, is gone;-mllvm,-mdebug-pass,-mlimit-float-precision,-ftime-report), or with-fno-integrated-cc1, whose jobs run as programs for which coretrace-compiler moves the process, take it alone, as coretrace-compiler asks.fix(input): bring the process back after a compilation that moves it, with its unit test, as reviewed at bbaab08: a compilation that takes the lock alone brings the process back to the directory it was in, before it releases the lock.perf(app): load the inputs at once, on two workers or min(N, 4) with --jobs=N:resolveLoadingJobs, insrc/app/AnalyzerApp.cpp, gives the number of loading workers; the loop of fix(app): load the shared modules one at a time, on the calling thread #285 becomes arunParallelWorkon that many. The other phases still takeresolveConfiguredJobs.perf(app): give back to the system the memory that the loading freed:malloc_trim(0)once the inputs are loaded, compiled under glibc only. glibc keeps the memory a compilation frees in the arena of the thread that ran it, for the rest of the run (fix(app): load the shared modules one at a time, on the calling thread #285).test(app)andtest(input): two checks inrun_test.py, described under Tests.docs(help),docs(readme)anddocs(changelog).A compile command whose directory does not exist still fails the analysis, with the message it gave before. coretrace-compiler reports such a directory, but compiles to memory all the same (CoreTrace/coretrace-compiler#264), so the analyzer checks the directory itself before compiling.
Measurements
On Linux
Measured on 2026-11-21 on a GitHub runner (run 44956551908): ubuntu-24.04 on x86-64, 4 CPUs, g++ 13.3, LLVM 20, glibc 2.39, each run in a cgroup of 4 CPUs and 6 GiB without swap.
--format=json --timing, no IR cache, an empty resource summary cache. Two builds, both with coretrace-compiler v0.13.0:min(--jobs, 4)workers, the freed memory given back after loading.This head differs from the second build by the bound without
--jobs(2 workers, where that build took 4), by the tests and by the documentation. Every run below gives--jobs.Medians of 3 runs; the builds alternate from one repetition to the next, and each passed the tests before the measures. The percentages compare those medians.
--jobsNot measured:
--jobsat this head. It loads on 2 workers and runs the other phases on every processor, where the runs at 2 jobs above ran both on 2.On macOS, before the rework
Measured on 2026-11-12, and on 2026-11-15 for 4 jobs: this branch as it was then, the inputs loading on
--jobsworkers without a bound, which is this head's loading at 2 and 4 jobs. macOS arm64 (M3, 8 cores), LLVM 20.1.2,--format=json --timing, no IR cache, an empty resource summary cache. Both builds use coretrace-compiler from source: main (f0a22d9) for db7fb25, CoreTrace/coretrace-compiler#262 for this branch. Medians of 5 runs, 3 for the 53 sources; the builds alternate within each repetition.--jobs--jobs=4row was measured apart, on the 53 sources only: this branch at e6ae53e, with coretrace-compiler fetched at the pinned commit, against db7fb25 built as above.--jobs=2, 239 MB to 328 MB for the 8 C++ files, 1.26 GB to 1.42 GB for the 53 sources; at--jobs=4, 1.35 GB to 1.62 GB for the 53 sources. The memory freed by the loading was not given back in that build.Tests
Two functional checks are added to
run_test.py. Each writes twelve C files that call one another in a chain, each reading a global of its own before any write, and runs the analyzer on them directly, without the runner's extra arguments.check_loading_jobs: the files are loaded without a cache, with--timing. An input logsCompilingwhen its load starts andBitcode parse done inonce its module is there; the check reads the log line after line and keeps the most inputs between the two at once. It expects 2 without--jobsand with--jobs=auto, on a machine of two processors or more,min(N, 4)with--jobs=Nfor 1, 2, 3, 4 and 8, and 4 at--jobs=8with--no-resource-cross-tuand--no-uninitialized-cross-tu.check_reports_of_an_empty_and_a_filled_compile_ir_cache: the files are analyzed at--jobs=1without a cache, then, without--jobsand with--jobs=4, from an empty compile IR cache and again from the cache that run filled. The four runs must give the diagnostics and the functions of the first one, compared without the diagnostics' ids, which follow their place in the report. The runs on a filled cache must logCompilation cache hitfor the twelve inputs, the runs on an empty one for none. This check also passes with main's loading: it guards the loads that fill the cache together.No build was made locally for this rework: the CI below is its validation. Before the push:
--jobsloads at once, with another report from the filled cache, and with an input missing from the cache.scripts/format-check.shwith clang-format 20,scripts/check-license-compliance.shand the commit checker pass.The unit test of the review fix,
testLoadLeavesTheProcessDirectory, is unchanged.CI at 3445f89
All analyzer module unit tests passed.andAll ownership engine unit tests passed.;check_loading_jobs, in each of the three jobs: 2 inputs loading at once without--jobsand with--jobs=auto; 1, 2, 3 and 4 at--jobs=1,2,3and4; 4 at--jobs=8, with the cross-TU summaries and without them. The runners have 4 processors on ubuntu-24.04 and 3 on macOS.check_reports_of_an_empty_and_a_filled_compile_ir_cache, in each of the three jobs: without--jobsand with--jobs=4, the run on an empty cache and the run on the cache it filled give the report of the run without a cache, and read 0 and 12 of the 12 inputs from the cache.For the review
scripts/ci/run_code_analysis.pyis not changed. It splits the inputs into one chunk per processor and runs one analyzer per chunk at once, without--jobsunless its caller passes one. Each of those analyzers loaded one input at a time on main and loads two at once here: the script's run holds up to twice as many compilations in progress. It is the entry point ofDockerfile.ciand the self-analysis step ofci.yml. That step ran 4 analyzers at once on 55 files and took 92 s in the run above; it took 55 to 107 s in recent runs of main and of four other branches, so this run does not tell the two loadings apart.analyzeWithSharedModuleLoading). Every run of more than one input goes there today, as its global read-before-write summaries need all the modules. The other path,analyzeWithoutSharedModuleLoading, still takes--jobsworkers that each load and analyze an input, and is reached with one input only. The last case ofcheck_loading_jobsfails the day a multi-file run takes it.check_loading_jobsneeds the loads to overlap to see the bound reached: twelve inputs that each include three standard headers. On the logs of the Linux measure, the 34 files of Lua reached 2 and 4 at once in each run.