Skip to content

Commit 09ae31a

Browse files
committed
perf(build): share precompiled headers for all targets
Our precompiled header setup has a few problems: * Some libraries, such as quick-lint-js-tool-lib, are not built with precompiled headers. This slows down incremental builds. * Some executables, such as the benchmarks, get their own precompiled headers. This slows down clean builds and also bloats disk usage. Fix these problems by building at most two precompiled headers (one for quick-lint-js-test and one for everything else) and using them for all quick-lint-js targets (quick_lint_js_add_library and quick_lint_js_add_executable). Development clean build of quick-lint-js and quick-lint-js-test: $ hyperfine --warmup=1 --prepare='rm -rf build && ./configure build' 'ninja -C build quick-lint-js-test quick-lint-js' Before: Time (mean ± σ): 12.686 s ± 0.068 s [User: 95.302 s, System: 7.395 s] Range (min … max): 12.620 s … 12.861 s 10 runs After: Time (mean ± σ): 12.326 s ± 0.095 s [User: 84.436 s, System: 7.015 s] Range (min … max): 12.238 s … 12.577 s 10 runs CI approximation (clean build, 2 cores, builds benchmarks and Visual Studio Code extension): $ hyperfine --warmup=1 --prepare='rm -rf build && ./configure build' 'ninja -C build -j2' Before: Time (mean ± σ): 63.348 s ± 0.087 s [User: 116.393 s, System: 8.127 s] Range (min … max): 63.189 s … 63.474 s 10 runs After: Time (mean ± σ): 48.508 s ± 0.030 s [User: 89.685 s, System: 6.250 s] Range (min … max): 48.449 s … 48.552 s 10 runs Benchmarks performed on my Apple M1 laptop with Clang 16.
1 parent 8e1f4c6 commit 09ae31a

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,32 @@ find_package(PythonInterp 3.7)
153153

154154
find_package(PythonInterp 3) # Force Python 3 (instead of Python 2).
155155

156+
# quick-lint-js-precompiled-headers is used by quick_lint_js_add_executable and
157+
# quick_lint_js_add_library.
158+
include(QuickLintJSTarget)
159+
find_package(Threads REQUIRED)
160+
quick_lint_js_add_library(
161+
quick-lint-js-precompiled-headers
162+
STATIC
163+
website/wasm/empty.cpp
164+
)
165+
target_link_libraries(
166+
quick-lint-js-precompiled-headers
167+
PUBLIC
168+
Threads::Threads
169+
simdjson
170+
)
171+
if (QUICK_LINT_JS_PRECOMPILE_HEADERS)
172+
target_precompile_headers(
173+
quick-lint-js-precompiled-headers
174+
PUBLIC
175+
<cmath>
176+
<cstring>
177+
<simdjson.h>
178+
<string>
179+
)
180+
endif ()
181+
156182
# 'tools' must come first because it optionally defines targets. Other
157183
# CMakeLists.txt files detect the presence of these targets.
158184
add_subdirectory(tools)

cmake/QuickLintJSTarget.cmake

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ function (quick_lint_js_add_executable TARGET)
1111
PRIVATE
1212
"${QUICK_LINT_JS_CXX_COMPILER_OPTIONS}"
1313
)
14+
if ("${TARGET}" STREQUAL quick-lint-js-test OR
15+
"${TARGET}" STREQUAL quick-lint-js-test-lex-unicode)
16+
# HACK(strager): Tests have their own precompiled headers.
17+
else ()
18+
quick_lint_js_use_default_precompiled_headers("${TARGET}")
19+
endif ()
1420
endfunction ()
1521

1622
function (quick_lint_js_add_library TARGET)
@@ -20,6 +26,22 @@ function (quick_lint_js_add_library TARGET)
2026
PRIVATE
2127
"${QUICK_LINT_JS_CXX_COMPILER_OPTIONS}"
2228
)
29+
if ("${TARGET}" STREQUAL quick-lint-js-precompiled-headers)
30+
# Don't use PCH when building PCH.
31+
else ()
32+
quick_lint_js_use_default_precompiled_headers("${TARGET}")
33+
endif ()
34+
endfunction ()
35+
36+
function (quick_lint_js_use_default_precompiled_headers TARGET)
37+
if (QUICK_LINT_JS_PRECOMPILE_HEADERS)
38+
target_link_libraries("${TARGET}" PRIVATE quick-lint-js-precompiled-headers)
39+
target_precompile_headers(
40+
"${TARGET}"
41+
REUSE_FROM
42+
quick-lint-js-precompiled-headers
43+
)
44+
endif ()
2345
endfunction ()
2446

2547
# quick-lint-js finds bugs in JavaScript programs.

src/CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -475,16 +475,6 @@ endif ()
475475
if (CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
476476
target_link_libraries(quick-lint-js-lib PUBLIC kvm)
477477
endif ()
478-
if (QUICK_LINT_JS_PRECOMPILE_HEADERS)
479-
target_precompile_headers(
480-
quick-lint-js-lib
481-
PUBLIC
482-
<cmath>
483-
<cstring>
484-
<simdjson.h>
485-
<string>
486-
)
487-
endif ()
488478

489479
if (QUICK_LINT_JS_FEATURE_DEBUG_SERVER)
490480
target_compile_definitions(

0 commit comments

Comments
 (0)