Changes between Initial Version and Version 1 of AnalyzingBuildPerformance


Ignore:
Timestamp:
Oct 6, 2021, 9:39:22 PM (3 years ago)
Author:
jer.noble@apple.com
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AnalyzingBuildPerformance

    v1 v1  
     1= Analyzing Build Performance =
     2
     3To effectively reduce build times, it is first important to understand where that time is being spent. This page documents various tools and techniques used to perform detailed analysis of where the complier is spending its time.
     4
     5== Clang 9+ ==
     6
     7Clang 9 has introduced a new flag, [https://releases.llvm.org/9.0.0/tools/clang/docs/ReleaseNotes.html#new-compiler-flags -ftime-trace], which will generate time-profile information as a .json artifact during compilation. These artifacts include timing information on a per-header, per-function, per-template, or even per-optimization level.
     8
     9== Building ClangBuildAnalyzer ==
     10
     11While per-object-file trace information is useful for uncovering what causes compiling a specific source file to take as long as it does, tracing overall build time requires summarizing those traces across the entire project. The same person who originally authored the Clang tracing patch also built a summarization tool using those per-object-file traces as input, [https://github.com/aras-p/ClangBuildAnalyzer ClangBuildAnalyzer].  Here's how to build ClangBuildAnalyzer with Xcode on macOS:
     12
     131. `git clone https://github.com/aras-p/ClangBuildAnalyzer`
     142. `cd ClangBuildAnalyzer/projects/xcode`
     153. `xcodebuild`
     164. Copy `build/Release/ClangBuildAnalyzer` to a location in `$PATH`
     17
     18== Building WebKit with tracing enabled ==
     19
     201. Clean your build directory (but make sure it still _exists_).
     212. `ClangBuildAnalyzer --start path/to/WebKitBuild`
     223. `make debug ARGS='OTHER_CFLAGS=-ftime-trace OTHER_CPLUSPLUSFLAGS=-ftime-trace' `
     23
     24Then, when the build is complete:
     254. `ClangBuildAnalyzer --stop path/to/WebKitBuild path/to/output/file`
     265. `ClangBuildAnalyzer --analyze path/to/output/file > path/to/text/file`
     27
     28ClangBuildAnalyzer writes a file with the current time to your build directory when run with `--start`. Then when run with `--stop`, it collects all of the trace files generated during that time window, and collates them into the output file. `--analyze` turns that into human-readable output. Profiling individual projects within WebKit would involve running steps 1-5 from within, e.g., the Source/WebCore directory.
     29
     30== Resolving Expensive Headers ==
     31
     32ClangBuildAnalyzer will generate a list of the ten most expensive (in terms of compilation time) headers encountered during the build. For example:
     33
     34{{{
     35*** Expensive headers:
     36832243 ms: /Volumes/Data/WebKit/Source/WebCore/bindings/js/JSDOMGlobalObject.h (included 246 times, avg 3383 ms), included via:
     37  JSMallocStatistics.o JSMallocStatistics.h JSDOMWrapper.h  (6515 ms)
     38  JSMemoryInfo.o JSMemoryInfo.h JSDOMWrapper.h  (6490 ms)
     39  JSInternalSettingsGenerated.o JSInternalSettingsGenerated.h JSDOMWrapper.h  (6473 ms)
     40  JSApplePayCancelEvent.cpp JSApplePayCancelEvent.h JSDOMWrapper.h  (6455 ms)
     41  JSInternalsSetLike.o JSInternalsSetLike.h JSDOMWrapper.h  (6435 ms)
     42  JSMockPageOverlay.o JSMockPageOverlay.h JSDOMWrapper.h  (6430 ms)
     43  ...
     44}}}
     45
     46From this we can see that JSDOMGlobalObject.h is a very expensive header; it contributes about 3.3s of compile time, on average, to every source file which includes it. And it is included 246 times, which given the WebKit unified build system, means it is included by a majority of source files in the WebCore project. For these expensive headers, its often the case that the "expensive" header is expensive due to including other expensive headers, and one approach to make that header less expensive is to forward declare types rather than include their definitions. In cases where inline implementations of methods make forward declaration impossible, those inline definitions can be moved into a `<Type>Inlines.h` file, and the original declarations annotated with `inline`. Source files which contain references to those inline functions must include the `<Type>Inlines.h` file, or the compile will generate a `-Wundefined-inline` error.
     47