diff --git a/.github/workflows/BuildAndTest.yml b/.github/workflows/BuildAndTest.yml index 99875827..73981f0b 100644 --- a/.github/workflows/BuildAndTest.yml +++ b/.github/workflows/BuildAndTest.yml @@ -25,6 +25,9 @@ concurrency: env: CPM_SOURCE_CACHE: ${{ github.workspace }}/.cache/CPM SCCACHE_GHA_ENABLED: 'true' + # The full tier of the desktop jobs (weekly, pull requests into and pushes to master, manual dispatch with repeat_desktop_tests) + # also runs the MSVC code analysis and compiles the examples; a pull request into develop does neither (#435, docs/BUILD_TIME_STUDY.md). + FULL_TIER: ${{ (github.event_name == 'schedule' || (github.event_name == 'pull_request' && github.base_ref == 'master') || (github.event_name == 'push' && github.ref == 'refs/heads/master') || (github.event_name == 'workflow_dispatch' && inputs.repeat_desktop_tests)) && 'true' || 'false' }} # Third-party actions are pinned to commit SHAs; GitHub-owned actions/* use version tags. jobs: @@ -84,6 +87,23 @@ jobs: container: ${{ matrix.use_image && fromJSON(format('{{"image":"{0}","credentials":{{"username":"{1}","password":"{2}"}},"options":"--shm-size=1g"}}', needs.linux-image.outputs.image, github.actor, github.token)) || '' }} steps: &desktop-steps - uses: actions/checkout@v7 + with: + # A pull request is checked out as a merge commit: its first parent is the base, so the changed files are one diff away. + fetch-depth: 2 + # The builds that prove the self-built environment reproducible and equal to the checked-in bundles take about 45 s. A + # pull request into develop that changes none of their inputs (what PrepareSelfBuildProject.cmake copies, and the CMake and + # workflow files that drive them) leaves them to the push to develop and to the master tier (#435). + - name: Decide whether the reproducibility builds run + shell: bash + run: | + reproducibility=true + if [ "$FULL_TIER" != true ] && [ "$GITHUB_EVENT_NAME" = pull_request ]; then + if ! git diff --name-only HEAD^1 HEAD | grep -qE '^(js/|examples/life/ui/|test/developer/|test/web/(CMakeLists\.txt|registry/)|test/cmake/(PrepareSelfBuildProject|CompareFiles|CheckSelfBuildRefresh|AssembleDeveloperFixtures)|include/webfront/system/|LICENSE$|\.github/workflows/BuildAndTest\.yml)'; then + reproducibility=false + fi + fi + echo "Reproducibility builds: $reproducibility" + echo "WEBFRONT_REPRODUCIBILITY=$reproducibility" >> "$GITHUB_ENV" # No step of a build or of its tests needs a JavaScript runtime or package manager: the runner has none from here on. - uses: ./.github/actions/remove-node - uses: ./.github/actions/setup-cmake @@ -120,15 +140,19 @@ jobs: command -v sccache sccache --version # ENABLE_CACHE controls automatic ccache discovery; the explicit sccache launcher stays enabled. + # The heavy unit tests are compiled four to a file (docs/BUILD_TIME_STUDY.md); the portability and sanitizer jobs keep one object per test file. - name: Configure run: >- cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DWEBFRONT_EMBED_CEF=OFF -DWEBFRONT_ENABLE_TESTING=ON -DENABLE_CACHE=OFF -DCMAKE_CXX_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_SCAN_FOR_MODULES=OFF + -DWEBFRONT_TEST_UNITY_BATCH=4 + -DWEBFRONT_TEST_REPRODUCIBILITY=${{ env.WEBFRONT_REPRODUCIBILITY }} + ${{ env.FULL_TIER == 'true' && '' || '-DWEBFRONT_MSVC_ANALYZE=OFF -DWEBFRONT_BUILD_EXAMPLES=OFF' }} ${{ matrix.options }} - name: Build - run: python3 test/tools/MeasureCommand.py --output build/build-resources.json -- cmake --build build --config ${{ matrix.build_type }} --parallel 2 + run: python3 test/tools/MeasureCommand.py --output build/build-resources.json -- cmake --build build --config ${{ matrix.build_type }} --parallel 4 - name: Ensure WebView2 Evergreen runtime if: runner.os == 'Windows' shell: pwsh diff --git a/cmake/CompilerWarnings.cmake b/cmake/CompilerWarnings.cmake index 8fb735a6..2657516a 100644 --- a/cmake/CompilerWarnings.cmake +++ b/cmake/CompilerWarnings.cmake @@ -4,6 +4,8 @@ function(set_project_warnings project_name) option(WARNINGS_AS_ERRORS "Treat compiler warnings as errors" ON) + # MSVC /analyze roughly doubles the front-end work of every unit (#435): OFF is for measuring that cost, not for CI. + option(WEBFRONT_MSVC_ANALYZE "Run the MSVC code analysis while compiling" ON) set(MSVC_WARNINGS /W4 # Baseline reasonable warnings @@ -35,6 +37,10 @@ function(set_project_warnings project_name) /permissive- # standards conformance mode for MSVC compiler. ) + if(NOT WEBFRONT_MSVC_ANALYZE) + list(FILTER MSVC_WARNINGS EXCLUDE REGEX "^/analyze") + endif() + set(CLANG_WARNINGS -Wall -Wextra # reasonable and standard diff --git a/cmake/RunWithDeadline.sh b/cmake/RunWithDeadline.sh index 7202dbe5..24310182 100755 --- a/cmake/RunWithDeadline.sh +++ b/cmake/RunWithDeadline.sh @@ -4,21 +4,44 @@ # the command started cannot outlive it. Exits with 124 on a timeout (the command was killed), else with its status. limit=$1 shift -set -m expired=$(mktemp -u) -"$@" & +# The command needs its own process group for the deadline to reach everything it started. Job control gives it one; dash +# without a terminal accepts `set -m` yet keeps job control off (and then a group kill reaches nothing), where setsid gives it one instead. +{ set -m; } 2>/dev/null +case $- in + *m*) "$@" & ;; + *) + if command -v setsid >/dev/null 2>&1; then + setsid "$@" & + else + "$@" & + fi + ;; +esac command_pid=$! +# Where the command has no group of its own (a shell without job control, and no setsid), the deadline walks its descendants. +kill_tree() { + for child in $(pgrep -P "$1" 2>/dev/null); do + kill_tree "$child" + done + kill -s KILL "$1" 2>/dev/null +} ( - sleep "$limit" + sleep "$limit" & + sleeper=$! + trap 'kill "$sleeper" 2>/dev/null; exit 0' TERM + wait "$sleeper" || exit 0 : > "$expired" - kill -KILL -- "-$command_pid" 2>/dev/null -) & + kill -s KILL -- "-$command_pid" 2>/dev/null || kill_tree "$command_pid" +# The watchdog must not hold the caller's output pipes: the caller waits for them to close, so a sleeping watchdog would +# delay a command that already finished until the deadline (30 s per Jasmine case under dash, which has no job control here). +) >/dev/null 2>&1 & watchdog_pid=$! wait "$command_pid" status=$? -kill -KILL -- "-$watchdog_pid" 2>/dev/null +kill -TERM "$watchdog_pid" 2>/dev/null # Whatever the command left behind in its group goes with it. -kill -KILL -- "-$command_pid" 2>/dev/null +kill -s KILL -- "-$command_pid" 2>/dev/null # Only the watchdog's flag makes a kill a timeout: an unrelated SIGKILL keeps its own status. if [ -e "$expired" ]; then rm -f "$expired" diff --git a/docs/BUILD_TIME_STUDY.md b/docs/BUILD_TIME_STUDY.md new file mode 100644 index 00000000..bec79c66 --- /dev/null +++ b/docs/BUILD_TIME_STUDY.md @@ -0,0 +1,66 @@ +# Pull-request CI time (#435) + +Pull-request runs of `BuildAndTest.yml` took about 6 minutes, or 20 when the pull request touched a header that every heavy +unit includes (`WebFront.hpp`: #400, #401, #428). The cause is compile time: about 26 translation units instantiate a full +application and cost 28 to 113 s each on MSVC, and a changed header misses the compiler cache for all of them. + +This page keeps what was measured and what was decided. The measurements come from GitHub-hosted runners, with a throwaway +workflow (in the history of pull request #436) that timed clean builds of the `tests` target with an empty compiler cache +(`cold`), a complete one (`warm`) and a complete one but for the files a pull request changes (`header`, `heavy-test`, +`light-test`). Hosted Windows runners vary by up to 1.5x between identical jobs, so Windows figures are the median of three +runs; Linux runs are steadier. + +## Decisions + +| Change | Effect | +|---|---| +| `--parallel 4` on the desktop builds | Linux `tests` 280 -> 170 s cold, `all` 520 -> 255-375 s; Windows `tests` 820 -> 640 s, `all` 1240 -> 1080 s. Peak memory stays under 1 GB. | +| The 13 heavy unit tests compile four to a file (`WEBFRONT_TEST_UNITY_BATCH=4` on the desktop jobs) | Windows cold 640 -> 355 s, `WebFront.hpp` changed 298 -> 111 s; Linux 202 -> 143 s and 88 -> 45 s. Less memory. | +| MSVC `/analyze` and the examples only in the master and weekly tier | `/analyze` is about 22 % of a Windows build (640 -> 497 s cold); the examples about 190 s of compiler time. | +| The reproducibility builds only when a pull request changes their inputs | About 45 s of worker time per job (`SelfBuildRepeat`, `SelfBuildRefresh`). | +| `JourneyEmbeddedBuild` and `LifeEmbeddedBuild` do not hold `webfront_port_9002` | They only compile; the lock had serialised 175 s (Linux) and 203 s (Windows) of tests. | +| `RunWithDeadline.sh` returns when its command does | Six Linux `ConsumerJasmine-*` cases waited 30 s each for nothing. | +| `DeveloperBrowserIntegration` in five parts | The dependency chain 186 -> 130 s on Linux; see below. | + +On a pull request that touches a core header (this one, after merging `develop`), the build step went from 328 to 85 s on Linux +and from 876 to 213 s on Windows, and the Windows job from about 20 to 7.7 minutes. + +## Measured and not adopted + +- **Precompiled headers.** sccache cannot cache an MSVC compilation that uses one, so a complete cache still recompiles every + unit (warm 32 -> 231 s on Windows) and the build needs 1.7 GB. On GCC it was slower than no precompiled header. +- **Grouping every test file** does not compile: the light units share helper names. Only the heavy units are grouped, and the + helpers they share were renamed. Groups of 4 beat groups of 6 and 12 in every scenario on both systems: a change to one + heavy test recompiles at most three others, and four groups still spread over four jobs. +- **Sharing instantiations between executables** (`extern template`). `life_journey` and `life_embedded` compile the same file + against different generated headers, and the developer application is instantiated with a different frontend or filesystem + in each executable. Identical function instantiations that occur in more than one unit of `tests` account for at most 9 % + of its compile time (Clang `-ftime-trace`, an upper bound). +- **Merging the small executables** (`jasmine_consumer`, `frontend_lifecycle`, `webview2_*`, 66 to 69 s each on MSVC): each + instantiates its own frontend type, and separate processes are part of what several cases prove. + +Where one compile goes (the floor of a heavy unit): `HelloWorld.cpp` costs 11 s with GCC (Debug, coverage: 21 % parsing, +23 % instantiation, 49 % optimisation and code generation), 22 s with Clang, 61 s with MSVC, where `WebFront.hpp` alone takes 8 s +to parse and the front end runs a second time for `/analyze`. + +## Run time + +The suite took 256 s (Linux) and 271 s (Windows). Its chain of dependent cases is `SelfBuildSession` -> `DeveloperFixtures` +-> `DeveloperBrowserIntegration` -> `LifeEmbeddedBuild` -> `LifeEmbeddedIntegration`: the first builds the environment under test +from the current sources and the later ones run it, so the order cannot be shortened. + +`SelfBuildSession` (59 s on a loaded Linux runner, 44 s on a quiet machine) is five `wf` commands in one browser session: +install 0.4 s, build the environment 8.5 s, its 121 JavaScript specs 16.3 s, a second build to prove the bytes equal 11.7 s, +and the refusal of a write outside the permissions 6.4 s. It is a product build and the test suite of the environment, run +by the product itself in WASM, so it cannot be a 3 s test. + +`DeveloperBrowserIntegration` was one script in one browser over one project (59 to 113 s). It is five parts +(`--part=app|scripts|typescript|jasmine|terminal`), each from its own project on a port the system picks, so none holds the port +lock. On a quiet Mac each part takes 3 to 6 s. On a four-vCPU runner the chain is shorter and the suite is not faster: +with four workers it is bound by its worker time divided by four (735 s / 4 = 184 s on Linux against a wall time of 195 s), +and the parts add worker time (each repeats the bootstrap, `wf create` and `wf init`, and five browsers contend for four cores). +Shortening the suite further means removing worker time; the largest cases on Linux are `AutomationMcpWindow` (62 s), +`SelfBuildSession` (59 s), `SelfBuildRefresh` (34 s) and `JourneyBuildSession` (31 s). + +`FrontendConsumerConfiguration` and `AddSubdirectoryNativeConsumer` (about 65 s each on Windows) configure and build separate +projects on purpose, each proving another option set from a clean state; they are off the chain. diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 539160d7..91447a20 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,19 @@ ## Unreleased +- Cut pull-request CI time (#435): the desktop jobs build with `--parallel 4` and compile the 13 heavy unit-test files four + to a file (`WEBFRONT_TEST_UNITY_BATCH`; the default build keeps one object per file, and `JsFunctionSenderTests.cpp`, + `CommandsTests.cpp`, `FrontendContractTests.cpp` and `BroadcastTests.cpp` name their helpers so that they can share one). + A pull request into `develop` no longer builds the examples or runs the MSVC code analysis (`WEBFRONT_MSVC_ANALYZE`, + default ON), nor the builds that prove the self-built environment reproducible unless it changes their inputs + (`WEBFRONT_TEST_REPRODUCIBILITY`, default ON); the weekly run, pull requests into and pushes to `master` do all three. + `JourneyEmbeddedBuild` and `LifeEmbeddedBuild` no longer hold the `webfront_port_9002` lock while they compile. + `DeveloperBrowserIntegration` is cut into five parts (`DeveloperBrowserIntegration`, `-scripts`, `-typescript`, + `-jasmine`, `-terminal`) that run in parallel from their own projects on ephemeral ports. `RunWithDeadline.sh` returns + when its command does instead of at the deadline, which took 30 s from each of the six `ConsumerJasmine-*` cases under + dash, and gives the command its own process group (`setsid`, or a walk of its descendants) where the shell has no job + control. `docs/BUILD_TIME_STUDY.md` holds the measurements and the decisions. + - Prefix WebFront's test options (#412): `WEBFRONT_ENABLE_TESTING`, `WEBFRONT_ENABLE_FUZZING`, `WEBFRONT_ENABLE_COVERAGE` and `WEBFRONT_ENABLE_SANITIZER_{ADDRESS,LEAK,UNDEFINED_BEHAVIOR,THREAD,MEMORY}` replace the unprefixed `ENABLE_*` names (still `OFF` by default). A parent project's own generic variables no longer build diff --git a/docs/DEVELOPER_ENVIRONMENT.md b/docs/DEVELOPER_ENVIRONMENT.md index ed8c4357..11529247 100644 --- a/docs/DEVELOPER_ENVIRONMENT.md +++ b/docs/DEVELOPER_ENVIRONMENT.md @@ -678,7 +678,7 @@ WKWebView and all 14 Linux CEF/Xvfb cases with both GCC and Clang in The packed 0.3.0 version passes WKWebView and all 14 GCC CEF/Xvfb cases in [run 39490581423](https://github.com/ambroise-leclerc/WebFront/actions/runs/39490581423). For Linux, select CEF and Xvfb instead; the same developer tests use the selected test frontend. -`DeveloperBrowserIntegration` exercises the real WASM compiler, local registry, `wf test` under the locked jasmine-core (pass, fail, pending, asynchronous failures, pattern, time limit, Ctrl+C, non-interactive report to C++), build without navigation, incremental dev reload/error/recovery/Ctrl+C, the Life preview, C++ generation/animation and repeatable header generation. Its CTest fixtures then build that +`DeveloperBrowserIntegration` (the application part: starter, build, `wf dev`, Life preview, embedding) and `DeveloperBrowserIntegration-scripts`, `-typescript`, `-jasmine` and `-terminal` exercise, in parallel and each from its own project, the real WASM compiler, local registry, `wf test` under the locked jasmine-core (pass, fail, pending, asynchronous failures, pattern, time limit, Ctrl+C, non-interactive report to C++), build without navigation, incremental dev reload/error/recovery/Ctrl+C, the Life preview, C++ generation/animation and repeatable header generation. Its CTest fixtures then build that **browser-generated** header and run `LifeEmbeddedIntegration` from an empty working directory with no developer callbacks. Deadline and grace-period regressions advance a scoped clock instead of sleeping for seconds; Worker startup, diff --git a/docs/TEST_PERFORMANCE.md b/docs/TEST_PERFORMANCE.md index 494b5223..de57d04b 100644 --- a/docs/TEST_PERFORMANCE.md +++ b/docs/TEST_PERFORMANCE.md @@ -120,7 +120,7 @@ sampled bounds, not precise unique-memory or process-creation counts. Pre-existi sccache server and its compiler children can fall outside this process family; sccache's own statistics complement the sampled build report. It preserves the measured command's failure status. -`DeveloperBrowserIntegration` emits begin/end timestamps for each major phase and every actual command, including +`DeveloperBrowserIntegration` and its four sibling parts emit begin/end timestamps for each major phase and every actual command, including expected failures. `DeveloperSpecs` reports both ends of each spec. The driver reports browser opening/return and shutdown, and every suite case, so process-exit costs remain distinguishable. `LastTest-.log` keeps the full transcript of each pass; the suite runner raises the CTest output cap to 2 MiB per case so JUnit retains these details too. The analyzer ranks the emitted @@ -172,3 +172,6 @@ compilation constraints before changing their coverage. GCC parallel coverage relies on libgcov's filesystem locking; filesystems without locking require isolated profiles and merging. macOS failures retain WebKit system/crash diagnostics and phase logs. + +Build-time measurements (compiler cache scenarios, grouping, precompiled headers, `/analyze`) and the decisions taken are in +[BUILD_TIME_STUDY.md](BUILD_TIME_STUDY.md). diff --git a/docs/TEST_TIERS.md b/docs/TEST_TIERS.md index c22ec6a8..a1cc42d3 100644 --- a/docs/TEST_TIERS.md +++ b/docs/TEST_TIERS.md @@ -21,7 +21,8 @@ cmake -DBUILD_DIR=build -DLABEL_EXCLUDE=portability -P test/cmake/RunTestSuite.c ## Following a browser test live -`DeveloperBrowserIntegration`, the `Automation*` cases and the `WfDriver*` cases run `wf` commands (`create`, `install`, +`DeveloperBrowserIntegration` and its siblings `DeveloperBrowserIntegration-scripts`, `-typescript`, `-jasmine` and `-terminal` +(the parts of `test/web/developer-specs.mjs`, which run in parallel on a port the system picks), the `Automation*` cases and the `WfDriver*` cases run `wf` commands (`create`, `install`, `build`, `dev`, `preview`, `embed`, ...) that can take several seconds each. CTest hides the output of a passing test, so to watch one: @@ -30,6 +31,12 @@ ctest --test-dir build -R DeveloperBrowserIntegration -V # CTest prints t ctest --test-dir build -R DeveloperBrowserIntegration -N -V # prints the command to run `developer_integration` directly ``` +Run `developer_integration` with a fixtures directory and an output directory but no `--part=` to play every part in one +session, as the test did before it was cut; `--part=app|scripts|typescript|jasmine|terminal` plays one. + +```bash +``` + The process prints a `Developer integration: