Repository navigation
Conversation
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
For --project (compile_commands.json, vcxproj and so on), a cached run is still quadratic. The PR stores the parsed files.txt as a std::map by value in Settings. But CppCheck::check(const FileSettings&) makes a full copy of Settings for every file (Settings tempSettings = mSettings; at lib/cppcheck.cpp:851), so every file now copies the N-entry map. Before, every file parsed files.txt. On 10000 files the cached --project run takes 25.9s with the PR and 24.0s on base, so the PR does not help there and is slightly slower. Plain file lists do get faster (1.5s vs 9.5s). Keeping the index behind a shared, immutable pointer in Settings would avoid the copy.
Apart from this, results did not change: in my tests the PR picks the same analyzer info files and reports the same findings as base. I found no other problems. comments.md has no earlier comments.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | Index copied with Settings for every file, so --project cached runs stay quadratic | AI review | lib/settings.h:156 |
🆕 New |
@g-chauvel, please fix, resolve or reply to the open and new comments: #1.
Testing
What I built and ran
- Built
cppcheckandtestrunnerfrom pr/ andcppcheckfrom base/. I did not build the GUI. ./testrunner TestAnalyzerInformation TestSummaries TestCppcheck TestSingleExecutorFS TestProcessExecutorFS TestThreadExecutorFS: 75 tests, 0 failed.pytest -k "builddir or build_dir or cppcheck_build"in test/cli: 53 passed, 1 skipped, 1 xfailed.- Correctness check: a project where
a.cappears twice (with different defines) andsub/a.conce, analysed twice with the build dir. PR and base give identical output on both runs and create the samea.a1..a3/a.s1..a3files.
Performance with --project
Generate 10000 files and a compile_commands.json for them:
mkdir src; for i in $(seq 1 10000); do printf 'int f%d(void) { return 0; }\n' $i > src/m$i.c; done
python3 -c "
import json,os
d=os.getcwd()
print(json.dumps([{'directory':d,'file':d+'/src/m%d.c'%i,'command':'gcc -c src/m%d.c'%i} for i in range(1,10001)]))" > cc.json
mkdir bd; cppcheck -q -j8 --cppcheck-build-dir=bd --project=cc.json
time cppcheck -q --cppcheck-build-dir=bd --project=cc.jsonCached run times (real):
| Files | base | PR |
|---|---|---|
| 2500 | 3.56s | 3.84s |
| 5000 | 8.31s | 8.85s |
| 10000 | 24.0s | 25.9s |
With a plain directory (src instead of --project) at 10000 files: PR 1.46s, base 9.52s, as the PR description says.
I interrupted the PR's --project run under gdb at random times. Both samples I looked at were copying std::map<std::tuple<std::string,...>>, which is buildDirFilesTxt, called from Settings::Settings (copy) ← CppCheck::check(const FileSettings&) at lib/cppcheck.cpp:851 ← SingleExecutor::check.
Automated review of fcfb4ee by Claude. The pull request was built and tested locally.
| std::string buildDir; | ||
|
|
||
| /** AnalyzerInformation::FilesTxt of buildDir, files.txt is read when it is empty */ | ||
| std::map<std::tuple<std::string, std::string, std::size_t>, std::string> buildDirFilesTxt; |
There was a problem hiding this comment.
AI review
This map is stored by value in Settings, and CppCheck::check(const FileSettings&) copies the whole Settings for every file (Settings tempSettings = mSettings;, lib/cppcheck.cpp:851). So with --project, every file copies all N entries and the cached run is still quadratic. The cost of reading files.txt has only moved into the copy.
Measured on a compile_commands.json with 10000 trivial files (cached run):
- PR: 25.9s
- base: 24.0s
- 2500 / 5000 files: 3.84s / 8.85s with the PR, 3.56s / 8.31s on base
gdb samples land in the _Rb_tree copy of this map inside Settings::Settings. Only the plain-files case benefits (1.5s vs 9.5s). Holding the index as std::shared_ptr<const AnalyzerInformation::FilesTxt> (or similar) would make the copy cheap.
AnalyzerInformation::getAnalyzerInfoFile()reads and parses the whole files.txt at each call, and it is called several times per file, so with--cppcheck-build-dirthe time is quadratic in the number of files (since 1.77). This PR parses files.txt once: the CLI and the GUI keep it inSettings::buildDirFilesTxtand pass it toAnalyzerInformation. Without it, files.txt is read as before.real 0m1.066sreal 0m0.182sreal 0m4.302sreal 0m0.477sreal 0m15.970sreal 0m1.215s