This is an archive of the discontinued LLVM Phabricator instance.

[clang][cli] Benchmark command line round-trip
AbandonedPublic

Authored by jansvoboda11 on Jan 27 2021, 4:17 AM.

Details

Reviewers
None
Summary

This patch adds a benchmark for command line round-tripping.

Below are the results of running command-line parsing, preprocessing and compilation of a minimal file (int main() { return 0; }) with 137 CC1 arguments (that's typical on macOS; on Linux CC1 usually gets half of that), in release build with assertions:

---------------------------------------------------------------------
Benchmark                              Time           CPU Iterations
---------------------------------------------------------------------
BM_CompilerInvocationCreate/0     145905 ns     145882 ns       4768
BM_CompilerInvocationCreate/1     432513 ns     432354 ns       1622
BM_Preprocess/0                  1442563 ns    1442200 ns        489
BM_Preprocess/1                  1748370 ns    1748310 ns        393
BM_Compile/0                     2656841 ns    2656802 ns        263
BM_Compile/1                     2971966 ns    2970355 ns        231

Command line parsing is ~3x slower. That makes sense given we're doing the parse twice and also generate the original command line from CompilerInvocation. The absolute delta is small though: ~0.3ms. Preprocessing is ~21% slower, compilation ~12% slower.

On a real-world compile of clang/lib/Frontend/CompilerInvocation.cpp with -O3, the command-line parsing time is naturally insignificant:

-----------------------------------------------------------------------
Benchmark                               Time            CPU Iterations 
-----------------------------------------------------------------------
BM_CompilerInvocationCreate/0      208180 ns      208155 ns       3352
BM_CompilerInvocationCreate/1      587957 ns      587869 ns       1183
BM_Preprocess/0                 403769607 ns   403672500 ns          2
BM_Preprocess/1                 405895925 ns   405802000 ns          2
BM_Compile/0                  22408258046 ns 22403926000 ns          1
BM_Compile/1                  22363847808 ns 22358900000 ns          1

Running check-clang and Clang's Frontend LIT tests doesn't show any measurable performance impact.

Diff Detail

Event Timeline

jansvoboda11 created this revision.Jan 27 2021, 4:17 AM
jansvoboda11 requested review of this revision.Jan 27 2021, 4:17 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 27 2021, 4:17 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
jansvoboda11 added inline comments.Jan 27 2021, 4:39 AM
clang/benchmarks/CMakeLists.txt
4

Not sure if we should do anything else here. I mostly cargo-culted this from clangd.

clang/benchmarks/CompilerInvocationBench.cpp
12

It would be nice to load this from a file (e.g. ./Inputs/short-args.txt).

What is the best approach here? Some options:

  • copy the .txt file to the build folder via CMake and load it using llvm::sys::fs::current_path,
  • leave the .txt file in source directory and hard-code the path via CMAKE_CURRENT_SOURCE_DIR,
  • require users to supply path to the .txt file through command line.
jansvoboda11 retitled this revision from [clang][cli] Benchmark command line round-trip to [WIP][clang][cli] Benchmark command line round-trip.Jan 28 2021, 8:42 AM

Remove hard-coded arguments

jansvoboda11 retitled this revision from [WIP][clang][cli] Benchmark command line round-trip to [clang][cli] Benchmark command line round-trip.Jan 28 2021, 10:38 AM
jansvoboda11 edited the summary of this revision. (Show Details)Jan 28 2021, 10:43 AM
This comment was removed by jansvoboda11.
jansvoboda11 abandoned this revision.Feb 19 2021, 5:09 AM

Benchmark compilation and preprocessing as well

jansvoboda11 abandoned this revision.Mar 24 2021, 3:24 AM
jansvoboda11 edited the summary of this revision. (Show Details)