Skip to content

ci(benchmarks): align combined modules in the in-repo runner - #4537

Open
cataphract wants to merge 7 commits into
masterfrom
glopes/benchmarks-in-repo
Open

cataphract wants to merge 7 commits into
masterfrom
glopes/benchmarks-in-repo

Conversation

@cataphract

@cataphract cataphract commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Binary layout changes can obscure the performance effect of a source change. Build both combined PHP extensions before timing either one, then align their common functions with llvm-bolt-align. The shared bp-runner continues to handle result conversion, comparison and publication.

This is stacked on #4506 and targets augusto/php-microbenchmarks-bp-runner. A single commit adds alignment to the migrated benchmark setup.

The PHP image copies the static LLVM 23.1.6 BOLT executable from the published, digest-pinned tool image. Comparisons default to pairwise alignment, with plain and off modes available as controls. Candidate-only runs currently default to plain BOLT; selecting a historical reference for those runs is deferred.

The runner rejects incomplete alignment and checks that benchmark setup has not replaced the rewritten module. Checkouts remain available for the shared analyzer to read revision metadata. Artifacts retain diagnostic logs without extra copies of the extension binaries.

Validation:

  • Eleven workflow tests passed on ubuntu-vm, covering all three scenarios, build/rewrite/run ordering, failure handling, module replacement and checkout retention.
  • The real bp-runner parsed all five in-repo configurations; the three alignment scripts passed ShellCheck, and shell syntax checks passed.
  • The preparation script aligned an existing compiled combined PHP extension, and both rewritten outputs passed tracer and AppSec API checks.
  • All six profiler workload variants passed through the actual revision runner, using CPUs 0–13 in place of CI's 34–47 on ubuntu-vm. This reused an existing compiled extension; it was an execution check, not a performance study.

Related: APMSP-4182.

@datadog-datadog-us1-prod

datadog-datadog-us1-prod Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Pipelines  Tests

✨ Unblock PR with BitsAI

❌ Errors

Your PR has failed checks. Please review the issues below and take necessary action before merging.

🚦 26 Pipeline jobs failed

DataDog/apm-reliability/dd-trace-php | test_web_symfony_latest: [8.5, apache2handler] — ❌ 1 test failed · 🔧 Needs a code fix, caused by this PR

View more details · View in GitLab

❌ testScenarioGetToMissingRoute from symfony-latest-test.DDTrace\Tests\Integrations\Symfony\Latest\CommonScenariosTest
       '#8 '
                                '{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/http-kernel/HttpKernel.php(80): '
                                'Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw()\n'
                                '#9 '
                                '{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/http-kernel/Kernel.php(155): '
                                'Symfony\\Component\\HttpKernel\\HttpKernel->handle()\n'
                                '#10 '
                                '{path}/tests/Frameworks/Symfony/Latest/vendor/symfony/runtime/Runner/Symfony/HttpKernelRunner.php(34): '
                                'Symfony\\Component\\HttpKernel\\Kernel->handle()\n'
                                '#11 '
...
DataDog/apm-reliability/dd-trace-php | test_extension_ci: [7.3, valgrind] — ❄️ 1 known flaky test · 🔄 may pass on retry

View more details · View in GitLab

↳ ❄️ Known flaky: Agentless endpoints fall back to datadoghq.com when DD_SITE is invalid from PHP.tmp.build_extension.tests.ext

DataDog/apm-reliability/dd-trace-php | test_extension_ci: [7.4, valgrind] — ❄️ 1 known flaky test

View more details · View in GitLab

↳ ❄️ Known flaky: tmp/build_extension/tests/ext/ffe/agentless_service_header.phpt (FFE agentless CDN requests send the service of the root spans in DD-Service) from PHP.tmp.build_extension.tests.ext.ffe

View all 26 failed jobs.

ℹ️ Info

No other issues found (see more)

❄️ No new flaky tests detected

🎯 Code Coverage (details)
• Patch Coverage: 100.00%
• Overall Coverage: 67.41% (-13.49%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: afe95cb | Docs | View more details | Give us feedback!

@cataphract
cataphract force-pushed the glopes/benchmarks-in-repo branch from 472509a to a8304c9 Compare November 20, 2026 17:38
Base automatically changed from augusto/php-microbenchmarks-bp-runner to master November 24, 2026 16:38
Incidental binary layout can obscure the performance effect of a source
change. Build both combined extensions before measuring either one and
align their common functions with the pinned static LLVM 23.1.6 tool.
The shared runner handles analysis and per-scenario publication, while
PHP scripts coordinate the paired builds its sequential template cannot.

Keep source checkouts available for revision metadata, verify that the
harness preserves rewritten modules, and retain diagnostic logs without
extra binary artifacts. Comparisons align by default; plain BOLT and
unprocessed runs provide controls, with plain BOLT for candidate-only
runs. Retain the upstream reporting, CPU partition and retry settings.
@cataphract
cataphract force-pushed the glopes/benchmarks-in-repo branch from a8304c9 to 4760098 Compare November 24, 2026 18:06
@cataphract
cataphract marked this pull request as ready for review November 24, 2026 18:06
@cataphract
cataphract requested review from a team as code owners November 24, 2026 18:06
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-24T18:08:03.492584Z 4760098 Draft marked ready
🔒 Security Review ✅ Completed 2026-11-24T18:10:40.637927Z 4760098 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4760098c13

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: FAIL

Default benchmark comparisons require BOLT, but the pinned CI image predates its addition, so comparisons stop before producing results. The image rebuild and repin identified in the description remain prerequisites.

Open Bits AI session

🤖 Bits Code Review · Commit 4760098

The comparison jobs now align the candidate and baseline extensions with
llvm-bolt-align before timing them, but MICROBENCHMARKS_CI_IMAGE still
pointed at dd-trace-php-152770667, which predates the Dockerfile change
that copies the tool in. Every default comparison run would therefore
have failed before producing results.

Rebuild the image from the current container/Dockerfile with the manual
build-benchmark-ci-images job and pin the resulting per-pipeline tag, as
the README prescribes. The Dockerfile runs `llvm-bolt-align --version`
while building, so a successful build confirms the tool is present.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cataphract
cataphract force-pushed the glopes/benchmarks-in-repo branch from 4760098 to f501780 Compare November 24, 2026 18:43

@datadog-datadog-us1-prod datadog-datadog-us1-prod Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

Available validation supports the scripted build, rewrite, and execution workflow. A full benchmark comparison in the pinned CI image remains unvalidated.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit f501780

@pr-commenter

pr-commenter Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Benchmarks [ tracer ]

Benchmark execution time: 2026-11-25 03:37:32

Comparing candidate commit c205c6b in PR branch glopes/benchmarks-in-repo with baseline commit cf5365b in branch master.

📊 Benchmarking dashboard

Found 0 performance improvements and 0 performance regressions! Performance is the same for 217 metrics, 1 unstable metrics.

Explanation

This is an A/B test comparing a candidate commit's performance against that of a baseline commit. Performance changes are noted in the tables below as:

  • 🟩 = significantly better candidate vs. baseline
  • 🟥 = significantly worse candidate vs. baseline

We compute a confidence interval (CI) over the relative difference of means between metrics from the candidate and baseline commits, considering the baseline as the reference.

If the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD), the change is considered significant.

Feel free to reach out to #apm-benchmarking-platform on Slack if you have any questions.

More details about the CI and significant changes

You can imagine this CI as a range of values that is likely to contain the true difference of means between the candidate and baseline commits.

CIs of the difference of means are often centered around 0%, because often changes are not that big:

---------------------------------(------|---^--------)-------------------------------->
                              -0.6%    0%  0.3%     +1.2%
                                 |          |        |
         lower bound of the CI --'          |        |
sample mean (center of the CI) -------------'        |
         upper bound of the CI ----------------------'

As described above, a change is considered significant if the CI is entirely outside the configured SIGNIFICANT_IMPACT_THRESHOLD (or the deprecated UNCONFIDENCE_THRESHOLD).

For instance, for an execution time metric, this confidence interval indicates a significantly worse performance:

----------------------------------------|---------|---(---------^---------)---------->
                                       0%        1%  1.3%      2.2%      3.1%
                                                  |   |         |         |
       significant impact threshold --------------'   |         |         |
                      lower bound of CI --------------'         |         |
       sample mean (center of the CI) --------------------------'         |
                      upper bound of CI ----------------------------------'

Unstable benchmarks

These benchmarks have a confidence interval too wide to call a change; treat them as noise rather than signal.

scenario:LaravelBench/benchLaravelDdprof-opcache

  • unstable execution_time [-698.694µs; +1129.774µs] or [-5.338%; +8.631%]

llvm-bolt-align pairs functions by symbol name, but it only pinned 60% of
them (17,600 of ~29,300) in the benchmark job even though the candidate and
baseline sources are nearly identical.

The unpinned 40% are exactly the Rust functions. The build runs Cargo in
tmp/build_combined, whose Cargo.toml reaches libdatadog as
../../libdatadog/...; those crates lie outside the workspace root, so Cargo
hashes their absolute path into -C metadata (47 crates differ between
/app/candidate and /app/baseline), and rustc derives the Rust symbol hashes
from it. Every Rust function therefore has a different name in each binary.

--remap-path-prefix and -C symbol-mangling-version=v0 do not change that
metadata, so they cannot fix it. Instead, build each revision in the same
scratch directory, keep the natural module, align the pair, and install the
aligned modules into the checkouts that the analyzer and the run steps still
use. Aligning two builds of the same source in different directories pinned
60%; the same source at one path pinned 100%, and the full job now pins
29,316 of 29,316 functions.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cataphract
cataphract requested a review from igoragoli November 25, 2026 02:07
The test drove run-benchmarks.sh against mocked git, make and llvm-bolt
commands. It only checked the ordering of the steps, never a real build or
alignment, so it could not catch what mattered here: the real job is the
authority on whether both revisions align. Drop it and the README paragraph
that told readers to run it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@igoragoli igoragoli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this! I commented on the biggest point that caught my eye.

A question: on PRs, the BOLT mode will be align. I assume the per team should evaluate the PHP's benchmark flakiness with align, right?

Pros:

  • The flakiness metrics would measure the benchmark design itself, not layout noise, which is what we intend to evaluate and optimize.
  • The consequence of flakiness we most want to cut on dd-trace-php is flaky PR comments, and these metrics would reflect exactly that.

Cons:

  • Master runs use plain, so benchmarks on master might be flakier than on PRs.

Here is an AI-generated review. Feel free to ignore, as they are rather minor issues:

AI-generated reviews

Medium

  1. README omits the fidelity consequence: the measured module is BOLT-rewritten with -fno-reorder-blocks-and-partition and --emit-relocs, so absolute numbers and the trend series do not reflect the production build; only in-job candidate-vs-baseline comparisons are meaningful.
  2. Documented local-reproduction command cannot run: the scripts dereference CI_PROJECT_DIR, CI_COMMIT_REF_NAME, CI_COMMIT_SHA, CI_PROJECT_NAME under set -u, but the reproduce block exports none of them and bp-runner injects none outside --local.
  3. Zero tests ship while the body advertises eleven: c205c6b5c deleted the only test (test_bolt_workflow.py, 249 lines) with a fair rationale, but the Validation section still claims those tests passed; mode selection, the log gate, and the module check are now unpinned.

Minor

  1. Latent footgun: setting BENCHMARK_SOURCE_ROOT to anything but /app makes the bp-runner analyzer (hardcoded /app paths, [ -d ] guard) silently skip all analysis while printing success. Nothing sets it today.
  2. Trap not failure-resilient: a failing mkdir/cp in the EXIT trap (ENOSPC) aborts it before rm -rf "$WORK_DIR", leaking the multi-GB scratch tree.
  3. Merge-base failure leaves no step context: exit 1 prints nothing, exit 128 prints only git's fatal: line.
  4. Script-name collision: same name as the macrobenchmarks' steps/run-benchmarks.sh from the cloned benchmarking-platform repo; a grep for a macro job log line lands on the wrong script.
  5. Stale tmp/ carryover: a checkout carrying a full tmp/build_combined tree plus a BOLT-installed module makes the scratch build a no-op and feeds BOLT output back into BOLT (manual runs only).
  6. Wasted copy: cp -a duplicates .git of 5 repos twice per job; nothing in the build reads it.
  7. Undocumented log-gate invariants: the gate hardcodes missed offset and count != 2 with no comment and no test; it fails closed, so worst case is a blocked job.
  8. Undocumented knobs: BOLT_BIN/BOLT_ALIGN_BIN have no other references and BOLT_BIN applies only in plain mode.
  9. Standalone leak: no trap, so a failed direct run leaves a multi-GB BUILD_ROOT.
  10. Divergent extension_dir resolution: php -n vs the Makefile's ini-loaded php; an extension_dir= ini setting would make the pre-install and first cmp guard a directory nothing loads.
  11. Stale CI doc: the PR adds tracer/ to the early-exit regex; the pre-PR regex matched the doc exactly, so the drift is new.
  12. Unqualified README claim: "Both revisions are compiled and aligned before either is measured" is false under BOLT_MODE=off.
  13. Stale PR body: says stacked on #4506 targeting augusto/php-microbenchmarks-bp-runner (base is master, #4506 merged), says "a single commit" (4 commits), and never mentions the tracer/ regex or artifacts: when: always.

# The shared analyzer reads Git metadata from these fixed checkout locations.
# Keep the checkouts until analysis finishes; only BOLT's scratch files are
# removed by this script's exit trap.
SOURCE_ROOT=${BENCHMARK_SOURCE_ROOT:-/app}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default is fine, but if BENCHMARK_SOURCE_ROOT is set, results will be saved outside the "fixed checkout locations" (/app/candidate/ and /app/baseline/, by default).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed in afe95cb. The override only existed for the unit test, which is gone, and the checkouts are now fixed at /app/candidate and /app/baseline.

@cataphract

Copy link
Copy Markdown
Contributor Author

@igoragoli Yes, flakiness should be evaluated with align, since that is what the PR comments use. Master is the exception: with no baseline it falls back to plain, so its series isn't comparable to the PR comparisons. In principle, master binaries could be aligned against the binary of the previous master run. Even if that is feasible, it is outside the scope of this PR, so I'll just note the caveat in the README.

cataphract and others added 3 commits November 25, 2026 12:45
The CI image copies llvm-bolt and llvm-bolt-align from a tool image whose
Dockerfile, patch and build job lived on a branch of another repository,
outside the review of this PR, even though the tool is only used here.

Move the image's sources (Dockerfile, bolt-align.patch, smoke test and
README) under .gitlab/benchmarks/container/llvm-bolt-align/ and add a manual
build-llvm-bolt-align-image job next to build-benchmark-ci-images, built by
the same template. Like the main image it is published under the benchmark
registry name, with a tag of its own (llvm-bolt-align-<pipeline id>) that is
unique per pipeline, so a rebuild cannot shift what older pipelines pulled.

Repin the FROM in container/Dockerfile to the image this job built, so the
tool the benchmarks use is the one defined and reviewed here.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tool

The CI image now builds from the llvm-bolt-align image defined in this
repository, not from the one built on a branch of another repository. Rebuild
it with build-benchmark-ci-images and pin the resulting tag, as the README
prescribes. The build log shows the new tool image in use
(`llvm-bolt-align --version`: LLVM 23.1.6).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
- Fix the BOLT section of the README: scope the "compiled and aligned"
  sentence to the modes that do it, say that master runs use plain processing
  and are not comparable to the aligned PR comparisons, and complete the
  local-reproduction environment (CI_PROJECT_DIR, CI_PROJECT_NAME,
  CI_COMMIT_REF_NAME, CI_COMMIT_SHA).
- Drop the BENCHMARK_SOURCE_ROOT override. Only the removed unit test used
  it, and the shared analyzer reads /app/candidate and /app/baseline, so any
  other location silently skips the analysis.
- Never build from a leftover tmp/ in the scratch copy, document what the
  alignment log gate checks, and drop the unused BOLT_BIN/BOLT_ALIGN_BIN
  overrides.
- Bring .claude/ci/benchmarks.md up to date: the trigger paths, the new
  image job, the description of the local flow and its Approach 1 (default
  tracer-only extension, not the combined one CI measures), and the services
  section (the dd-trace-ci images have no MySQL/Redis, which
  composer_tests_update also needs). Document how to run the full CI flow with
  BOLT alignment locally.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@cataphract

Copy link
Copy Markdown
Contributor Author

@igoragoli Addressed in afe95cb: the master caveat in the README (M1, shortened), the local-reproduction environment (M2), the BENCHMARK_SOURCE_ROOT override, stale tmp/ in the scratch copy (m5), a comment on the log gate (m7), the unused BOLT_BIN/BOLT_ALIGN_BIN overrides (m8), the CI doc's trigger list (m11) and the README sentence about BOLT_MODE=off (m12). The PR description is being updated for M3 and m13.

Not changed: the exit trap (m2) and standalone-run trap (m9) only affect a throwaway container or a manual run; the merge-base message (m3) can't realistically fail, since the candidate is a full clone and the base always exists on origin; the .git copy (m6) takes under 10 s next to a 10-minute build; extension_dir (m10) is the same with and without -n in the CI image, and the cmp checks fail the job if it ever differs; the script name (m4) is shared with the macrobenchmarks' script from another repository, but they live in different directories and are never confused in the job definitions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants