Menu

-U slows down runtime

2020-08-10
2021-03-12
  • Fabian Cenedese

    Fabian Cenedese - 2020-08-10

    Hi

    There are several posts and questions about speeding up cppcheck. Me too I've run into a speed problem. Analyzing our codebase takes about a day with --force. Some #ifdefs don't need to be checked in all variants so I tried to -D and -U some of them in hope of bringing down execution time because less combinations need to be checked. However exactly the opposite happened. Here are some numbers:

    cppcheck file.cpp --force (and some other parameters but no -D or -U)
    135 config combinations
    26s

    Adding some -U parameters reduced the config combinations but also increased running time.
    5 -U, 120 configs
    30s

    7 -U, 111 configs
    36s

    10 -U, 100 configs
    37s

    With about 50 -U parameters the memory consumption exploded repeatedly to over 5GB and I killed cppcheck after about half an hour as it never even started printing the first "Checking file.cpp:..." message.

    Why do less configs to check need more time? And how can I bring down cppcheck execution time?
    The cpp file I tried here is less than 300 lines and has no #ifdef directive in it. Of course it includes
    header files which then have #ifdef directives but it doesn't make sense to check all variants of
    the include blockers #ifndef/#define, that's why I wanted to predefine them.

    Thanks

     
  • Daniel Marjamäki

    Interesting. I spontaneosly would have thought that -U should speed up cppcheck.

    Of course it includes header files which then have #ifdef directives but it doesn't make sense to check all variants of the include blockers #ifndef/#define, that's why I wanted to predefine them.

    You should not normally use -D or -U for include guards. Can you show an example where cppcheck tries all variants for include guards?

     
  • Fabian Cenedese

    Fabian Cenedese - 2020-08-11

    It seems that cppcheck doesn't understand some #if variants. It works using #ifndef but not in the following way:

    file.cpp:
    #include "file1.h"

    file1.h, file2.h, file3.h, fle4.h all in this way:

    #if !defined( INC_FILE1_H )
    #define INC_FILE1_H
    #include "file2.h"
    #endif
    

    Then all INC definitions are checked separately:
    cppcheck.exe --force file.cpp
    Checking file.cpp ...
    Checking file.cpp: INC_FILE1_H...
    Checking file.cpp: INC_FILE2_H...
    Checking file.cpp: INC_FILE3_H...
    Checking file.cpp: INC_FILE4_H...

    About the slow down: Is there some lookup of definitions that gets inefficient if there are many predefined -D/-U definitions? That's one thing that could explain it. However I couldn't reproduce such a dramatic slow down with this simple example. I guess it needs some real life code to happen.

    Thanks

     
  • Daniel Marjamäki

    Thanks! I consider that to be a bug then. I created this ticket: https://trac.cppcheck.net/ticket/9832

    Is there some lookup of definitions that gets inefficient if there are many predefined -D/-U definitions?

    I spontaneosly do not think so, it's a binary tree lookup.. but well obviously something is slow.

     
  • Daniel Marjamäki

    For your information I fixed 9832 issue now. Hope it will work better..

     

Log in to post a comment.