Code::Blocks Forums
User forums => Help => Topic started by: christo on May 05, 2024, 12:57:04 pm
-
Seeing high CPU usage by codeblocks, more than that of gcc, during compilation. I'm working external makefile project (makefile generated by cmake), and lot of verbose is enabled.
When analysed by perf, pcre2_match_32 is taking most of the CPU. Cause is that each of the build log line is check against 34 regular expressions.
I'm not much familiar with regex, but can anything to be done to improve the performance here?
-
I believe that there are a lot of codes to parse the compiler log message. So, if the compiler generate a lot of warnings, it takes a lot of time to parse those output.
So, sometimes, the building stage is really slow. :(
Not sure how to improve.
If I remember correctly, I have added some checks for the return line encoding, see this: The encoding text from GCC compiler should be UTF8 by default? (https://forums.codeblocks.org/index.php/topic,25162.msg171554.html#msg171554)
-
Some regex implementations are known to perform badly. For details see e.g:
see:
https://stackoverflow.com/questions/70583395/why-is-stdregex-notoriously-much-slower-than-other-regular-expression-librarie (https://stackoverflow.com/questions/70583395/why-is-stdregex-notoriously-much-slower-than-other-regular-expression-librarie)
https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2019/p1433r0.pdf (https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2019/p1433r0.pdf)
https://github.com/hanickadot (https://github.com/hanickadot)
https://www.youtube.com/watch?v=7-aXp-u6008&ab_channel=NDCConferences (https://www.youtube.com/watch?v=7-aXp-u6008&ab_channel=NDCConferences)
or search for slow c++ regex.
-
I would suggest disabling all the CB plugins you are not using or try selecting a different default compiler to see if any difference happens.
Edit: Also, change the project compiler and see if that helps.
Tim S.
-
Thank you for the quick responses.
Issue is not only when there are lot of warnings, but also when there is lot of verbose. I use external makefile project, makefiles are generated by CMake with verbose enabled, which is in turn done by Yocto. Turning off verbose is not an option for me.
I think solution is to avoid as many regex matching as possible. Attaching a patch where a token string is added corresponding to each regex where possible in such a way that if the string is not present in the compiler output line, we can be sure that matching will fail.
So check if the token string is present in each line. If not present, don't do regex matching for that regex. If present, do matching as normal.
This significantly improved my build time. I think it will improve build time of normal CB projects projects as well. I've done only limited testing with this.
-
Have you noted improvements in start up time?
-
Integrated ctre which is mentioned in the links provided by @blauzahn and tested, performance is much better.
With ctre, we can't use xml for storing the regex, it should be added to the code. I've done the changes such that if there is any regex in the xml file, it would be used by old method, and if not matched, ctre match is used. This way, regex can be tested using the xml, once finalized, add it to the code. Please note, this change requires c++20.
Attaching patch
-
Attaching perf output with and without ctre