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.
There was a problem hiding this comment.
Done, the index is now a std::shared_ptr<const ...> in Settings. Settings::summaryReturn (one entry per function of the project) was copied for each file the same way, so it is shared too. Cached run with --project, 10000 files: 8.5 s before this PR, 2.8 s now, the timings are in the description.
fcfb4ee to
f1ed8e3
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. The one earlier finding (C2) is fixed. buildDirFilesTxt and summaryReturn are now shared_ptr<const ...> in Settings, so copying Settings for each file no longer copies the index. With --project, a cached run on 5000 files now takes 4.95s with the PR and 9.19s on base. For the same file, cfg and fsFileId, the index picks the same afile as the old linear search: emplace keeps the first entry, just as the old loop returned the first match. Results and the analyzer info files written to the build dir were the same as base in every case I tried.
Comments
| # | Comment | By | Where | Status |
|---|---|---|---|---|
| 1 | files.txt index stored by value in Settings is copied per file, so --project cached runs stay quadratic | AI review | lib/settings.h:156 |
✅ Fixed |
Testing
What I built and ran
- Built
cppcheckandtestrunnerfrom pr/ andcppcheckfrom base/. - Built the GUI and its tests with CMake.
QT_QPA_PLATFORM=offscreen ctest --test-dir build-gui -R test-: 5 of 5 passed. ./testrunner TestAnalyzerInformation TestSummaries TestCppcheck TestSingleExecutorFS TestProcessExecutorFS TestThreadExecutorFS TestSettings: 89 tests, 0 failed.pytest -k "builddir or build_dir or cppcheck_build"in test/cli, which includes the newtest_builddir_summary_compdb: 54 passed, 1 skipped, 1 xfailed.
Correctness: PR compared with base
- Duplicate files in a compile_commands.json:
a.cwithout and with-DX,./sub/a.candb.c, analysed twice with a build dir. I ran this single-job, with-j2(process executor) and with-j2 --executor=thread. The PR and base gave the same findings on both runs and created the same files (a.a1..a3,a.s1..a3,b.a1,b.s1). - Plain file list with path variants:
a.c ./sub/a.c b.c sub/../a.c. Same output and the same build-dir files as base. --enable=information --suppress=nullPointer:b.c: the unmatched suppression is reported the same way as on base, on the first run and on the cached run. This coversreportUnmatchedSuppressions, which now uses the index.
Performance (cached run, 5000 trivial files)
--projectwith a compile_commands.json: PR 4.95s, base 9.19s.- Plain directory: PR 0.61s.
Automated review of f1ed8e3 by Claude. The pull request was built and tested locally.
|
Test results for commit f1ed8e3 (tools/test-my-pr.py, main compared to this PR): Test: http://ec2-51-20-36-10.eu-north-1.compute.amazonaws.com/pr-9096/ Posted automatically by the cppcheck PR test runner. +N: warnings only with this PR, -N: warnings only with main. The AI review is written by Claude and can be wrong. |
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.With
--project,Settingsis copied for each file. The index andSettings::summaryReturn(the functions of the project that return, loaded from the build dir) are shared between the copies instead of being copied.real 0m1.045sreal 0m0.184sreal 0m4.142sreal 0m0.471sreal 0m16.714sreal 0m1.197sWith
--project:real 0m2.805sreal 0m1.371sreal 0m8.516sreal 0m2.817sreal 0m27.805sreal 0m5.468s