Skip to content

perf(build): set -Ctarget-cpu for Graviton2 / x86-64-v2#1274

Draft
duncanista wants to merge 1 commit into
jordan.gonzalez/cold-start-instrumentation/featurefrom
jordan.gonzalez/target-cpu/feature
Draft

perf(build): set -Ctarget-cpu for Graviton2 / x86-64-v2#1274
duncanista wants to merge 1 commit into
jordan.gonzalez/cold-start-instrumentation/featurefrom
jordan.gonzalez/target-cpu/feature

Conversation

@duncanista

Copy link
Copy Markdown
Contributor

Please include Jira ticket in title.

Jira: none yet — add before marking ready.

🚧 DRAFT — stacked on #1271 (jordan.gonzalez/cold-start-instrumentation/feature). Review/merge that first; this PR's base will retarget to main once #1271 lands.

Overview

Pin -Ctarget-cpu per build platform in both compile Dockerfiles
(images/Dockerfile.bottlecap.compile and
images/Dockerfile.bottlecap.alpine.compile).

The Lambda CPU is known at build time:

  • arm64 → Graviton2 → -Ctarget-cpu=neoverse-n1
  • x86_64-Ctarget-cpu=x86-64-v2 (the universally-safe baseline)

Mechanism / why: by default rustc generates code for a generic CPU of
the target arch. Telling the compiler the exact microarchitecture lets
codegen use the ISA extensions actually present on Lambda hosts. This
mostly benefits hot, vectorizable paths exercised during init —
TLS/crypto handshakes and (de)compression — so it targets the cold-start
work this stack is about.

Why x86-64-v2 and not v3 (important): x86-64-v3 (AVX2/BMI2/FMA) is
not guaranteed across every x86 host Lambda may schedule us onto. If
the binary is built for an ISA the host lacks, it does not degrade
gracefully — it crashes with SIGILL (illegal instruction) the first
time such an instruction executes. x86-64-v2 (SSE4.2 era) is supported
on all current Lambda x86 hardware, so it is the safe choice. arm64 has a
single known CPU (Graviton2), so neoverse-n1 is exact.

Implementation detail: a small shell conditional sets TARGET_CPU from
${PLATFORM} and the value is appended to the already-exported
RUSTFLAGS. In the alpine Dockerfile the linker-flags export is x86_64-only,
so the aarch64 path now also exports RUSTFLAGS (preserving the base
-Cpanic=abort) to carry -Ctarget-cpu. All existing flags are preserved.

Dockerfile-only change; no Rust source changes.

Testing

  • Verified the shell conditional resolves correctly for both aarch64
    (neoverse-n1) and x86_64 (x86-64-v2), and that sh -n parses both
    build branches.
  • Not docker-built locally. CI is the source of truth for the actual
    cross-compiles. A wrong/over-aggressive ISA would surface as a SIGILL
    at runtime, so the conservative x86-64-v2 baseline is intentional.

Lambda CPUs are known at build time: arm64 is Graviton2 (neoverse-n1)
and x86_64 is targeted at the universally-safe x86-64-v2 baseline.
Pin -Ctarget-cpu per PLATFORM in both compile Dockerfiles so codegen
can use the available ISA extensions (helps crypto/compression during
init). x86-64-v3 is deliberately avoided: it is not guaranteed across
all Lambda x86 hosts and a wrong ISA surfaces as SIGILL at runtime.
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jun 24, 2026

Copy link
Copy Markdown

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 5 Pipeline jobs failed

DataDog/datadog-lambda-extension | e2e-test-status (amd64)   View in Datadog   GitLab

DataDog/datadog-lambda-extension | e2e-test-status (amd64, fips)   View in Datadog   GitLab

DataDog/datadog-lambda-extension | integration-suite: [lmi]   View in Datadog   GitLab

View all 5 failed jobs.

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: f3a5314 | Docs | Datadog PR Page | Give us feedback!

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.

1 participant