perf(build): set -Ctarget-cpu for Graviton2 / x86-64-v2#1274
Draft
duncanista wants to merge 1 commit into
Draft
Conversation
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.
|
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please include Jira ticket in title.
Jira: none yet — add before marking ready.
Overview
Pin
-Ctarget-cpuper build platform in both compile Dockerfiles(
images/Dockerfile.bottlecap.compileandimages/Dockerfile.bottlecap.alpine.compile).The Lambda CPU is known at build time:
-Ctarget-cpu=neoverse-n1-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) isnot 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 supportedon all current Lambda x86 hardware, so it is the safe choice. arm64 has a
single known CPU (Graviton2), so
neoverse-n1is exact.Implementation detail: a small shell conditional sets
TARGET_CPUfrom${PLATFORM}and the value is appended to the already-exportedRUSTFLAGS. 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
aarch64(
neoverse-n1) andx86_64(x86-64-v2), and thatsh -nparses bothbuild branches.
cross-compiles. A wrong/over-aggressive ISA would surface as a SIGILL
at runtime, so the conservative
x86-64-v2baseline is intentional.