This is an archive of the discontinued LLVM Phabricator instance.

[clang-format][NFC] Skip unneeded calculations
AbandonedPublic

Authored by HazardyKnusperkeks on Nov 20 2022, 3:04 AM.

Details

Summary

For UT_Never the remaining results of the max() function are not needed, introduce a fast path for UT_Never.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptNov 20 2022, 3:04 AM
HazardyKnusperkeks requested review of this revision.Nov 20 2022, 3:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 20 2022, 3:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
owenpan added inline comments.Nov 20 2022, 7:00 PM
clang/lib/Format/WhitespaceManager.cpp
1433–1440

So that we don't have to worry about signed vs unsigned.

1434–1436

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.

clang/lib/Format/WhitespaceManager.cpp
1434–1436

The UT_Never case would be faster, if that would be measurable I don't know.

owenpan added inline comments.Nov 21 2022, 2:17 PM
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 patchAfter Patch
Run 112769ms12535ms
Run 213703ms12456ms
Run 313305ms12470ms
Avg13259ms12487ms

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 1Run 2Run 3Average
w/o patch50.107s50.082s50.120s50.103s
w/ patch50.031s49.998s50.094s50.041s

To my surprise, tools/clang/unittests/Format/FormatTests with the patch ran a little bit slower:

Run 1Run 2Run 3Average
w/o patch2707ms2697ms2710ms2705ms
w/ patch2720ms2719ms2724ms2721ms

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.