For UT_Never the remaining results of the max() function are not needed, introduce a fast path for UT_Never.
Details
Diff Detail
Unit Tests
Event Timeline
clang/lib/Format/WhitespaceManager.cpp | ||
---|---|---|
1434–1436 | The UT_Never case would be faster, if that would be measurable I don't know. |
clang/lib/Format/WhitespaceManager.cpp | ||
---|---|---|
1434–1436 | Probably negligible. Can we keep the current code which encapsulates the handling of UT_Never within appendIndentText? |
Reverted the changes in the switch. We now only have a fast path.
On my machine 4 consecutive runs of the clang format unittests, the last three times (as reported by gtest) are:
Before patch | After Patch | |
Run 1 | 12769ms | 12535ms |
Run 2 | 13703ms | 12456ms |
Run 3 | 13305ms | 12470ms |
Avg | 13259ms | 12487ms |
That would be 6% speedup, more than I'd excpected.
Release Build 32 Bit Windows.
I ran (on macOS Ventura) the release build of clang-format 8627811 on the entire clang codebase and saw only a 0.12% reduction in runtime, which is what I expected.
Run 1 | Run 2 | Run 3 | Average | |
w/o patch | 50.107s | 50.082s | 50.120s | 50.103s |
w/ patch | 50.031s | 49.998s | 50.094s | 50.041s |
To my surprise, tools/clang/unittests/Format/FormatTests with the patch ran a little bit slower:
Run 1 | Run 2 | Run 3 | Average | |
w/o patch | 2707ms | 2697ms | 2710ms | 2705ms |
w/ patch | 2720ms | 2719ms | 2724ms | 2721ms |
The refactoring std::max(0, C.Spaces) part still looks good though, but probably it's not worth it to have a patch just for that.
Doing this would lose some of the abstraction we have now without any gain in performance? Then we should leave it (and appendIndentText below) as is.