Author Topic: High CPU usage during build operation when verbose is enabled  (Read 5010 times)

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 32
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?

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 6036
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: High CPU usage during build operation when verbose is enabled
« Reply #1 on: May 05, 2024, 01:23:23 pm »
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?

If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.


Offline stahta01

  • Lives here!
  • ****
  • Posts: 7679
    • My Best Post
Re: High CPU usage during build operation when verbose is enabled
« Reply #3 on: May 05, 2024, 07:00:38 pm »
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.
« Last Edit: May 05, 2024, 09:22:40 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 32
Re: High CPU usage during build operation when verbose is enabled
« Reply #4 on: May 06, 2024, 05:57:15 am »
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.
« Last Edit: May 06, 2024, 08:09:48 am by christo »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1632
Re: High CPU usage during build operation when verbose is enabled
« Reply #5 on: May 20, 2024, 12:34:08 pm »
Have you noted improvements in start up time?


Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 32
Re: High CPU usage during build operation when verbose is enabled
« Reply #6 on: June 12, 2024, 05:10:26 am »
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

Offline christo

  • Multiple posting newcomer
  • *
  • Posts: 32
Re: High CPU usage during build operation when verbose is enabled
« Reply #7 on: June 12, 2024, 05:11:25 am »
Attaching perf output with and without ctre