[cmake-developers] Profile Cmake scripts

Daniel Pfeifer daniel at pfeifer-mail.de
Tue Jan 5 07:33:00 EST 2016


On Tue, Jan 5, 2016 at 9:18 AM, Bartosz Kosiorek <gang65 at poczta.onet.pl> wrote:
>
> Hi Ben.
>
> 2016-01-04 17:39 GMT+01:00 Ben Boeckel <ben.boeckel at kitware.com>:
>>
>> The
>> big remaining problem is passing char* as an argument where functions do
>> std::string(arg) right away. I fixed all of those which did explicit
>> std::string conversions (via assignment or otherwise), but those which
>> are conditional should get std::string overloads to avoid a
>> malloc/copy/free penalty. There is a *lot* of work here though. The
>> branch I had been working on (which is now woefully out-of-date) is 100
>> commits long.

This improvement should be semi-automated with clang-tidy. We have
many functions that take `const char*` and are called by passing a
`string.c_str()`. The function signature should be changed to `const
std::string&` manually, but changing all the call sites should be done
automatically (ideally by kwrobot, periodically, on multiple
platforms).

Here is how to run clang-tidy on projects built with CMake:

$ cd <build dir>
$ cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON <source dir>
$ run-clang-tidy.py -p <build dir> -fix
-checks='-*,readability-redundant-string-cstr' <source dir>/Source/

The run-clang-tidy.py script is here:
https://llvm.org/svn/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/run-clang-tidy.py
The `-fix` argument tells clang-tidy to fix the violations inplace.
Without this argument the diagnostics are just printed.

I wanted to demonstrage the ability of the `redundant-string-cstr`
checker, but apparently there are no violations found.
I have attached a patch that was generated by the
`container-size-empty` checker.
Please don't apply it. Such changes should be performed by kwrobot.

You can output all possible checks with:

$ clang-tidy -p <build dir> -checks='*' -list-checks <source dir>

> That's great news.
> What is the branch name/link to these improvement?
> Is it possible to push these improvements partially?
>
> Maybe CMake community could continue working on that improvement?
> It will be great to create ticket, in which propose solution will be
> described.
>
> BTW: Do you know why the Xcode and MS Visual Studio is slower than CMake one
> ?
>
> Here is the benchmarks for my internal project:
>
> Xcode generation:
>    real 6m31.733s
>    user 4m51.862s
>    sys 0m20.268s
>
> Make generation:
>    real 4m45.089s
>    user 2m56.117s
>    sys 0m17.481s
>
> Ninja generation:
>   real 2m48.585s
>   user 2m30.712s
>   sys 0m6.313s

Generators for Xcode and Visual Studio have to generate more files.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-demonstrate-clang-tidy.patch
Type: text/x-patch
Size: 1935 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20160105/9ed27d29/attachment.bin>


More information about the cmake-developers mailing list