build: compile docker image for x86-64-v3 target#311
Conversation
Compile the release binary with target-cpu=x86-64-v3 plus pclmulqdq so it
uses AVX2, BMI1/2, LZCNT, and carryless-multiply on any host from Haswell
(2013) / Zen+ (2018) onward. Measured on a Skylake-SP server (the class
still common in fleet hosts) over a 400-slot devnet, this gets ~3.1x the
aggregation throughput of the default x86-64 build and ~1.15x the throughput
of -Ctarget-cpu=native -- the latter because aggressive AVX-512 use triggers
core downclocking on this generation, so staying on AVX2 keeps the clock
higher.
Two Docker plumbing fixes are needed to make the config actually take effect:
* COPY .cargo/ before the cargo-chef cook step so dependency builds see
target.rustflags. Otherwise chef cook emits deps with default flags and
the final cargo build reuses them.
* Drop the RUSTFLAGS ARG/ENV. An empty RUSTFLAGS env var overrides
target.<triple>.rustflags from .cargo/config.toml (cargo precedence),
so leaving ENV RUSTFLAGS="" in place silently nullifies the config.
🤖 Kimi Code ReviewOverall Assessment: The PR correctly fixes a Docker build issue where Critical: Hardware Compatibility (
Minor: Redundant Target Features (
Correct: Cargo Chef Fix (Dockerfile:18-21, 33-36) Security/Build: Docker Context ( Note: Platform Specificity Summary: Code changes are technically correct and well-commented, but Item 1 (compatibility) should be addressed before merge or clearly documented. Automated review by Kimi (Moonshot AI) · kimi-k2.5 · custom prompt |
🤖 Codex Code Review
No consensus-layer logic is touched here, so I did not find fork-choice / STF / attestation-specific issues in this PR. The main concern is release portability and operational safety of the produced binaries. Automated review by OpenAI Codex · gpt-5.4 · custom prompt |
🤖 Claude Code ReviewHere is the review: PR Review:
|
Greptile SummaryThis PR compiles the release Docker image for the x86-64-v3 microarchitecture level, enabling AVX2/BMI1/BMI2/LZCNT/PCLMULQDQ instruction usage and delivering a reported ~3× aggregation speedup on Skylake-SP hardware. It also fixes two Docker plumbing bugs: copying Confidence Score: 5/5Safe to merge; changes are well-reasoned and the two P2 findings are informational only. All findings are P2: one notes that No files require special attention.
|
| Filename | Overview |
|---|---|
| .cargo/config.toml | New file setting x86-64-v3 target-cpu and explicit feature flags for x86_64-unknown-linux-gnu; +pclmulqdq is redundant with the v3 level but safe in practice. |
| .dockerignore | Adds !.cargo/ whitelist rule so the new .cargo/config.toml is included in the Docker build context. |
| Dockerfile | Copies .cargo/ before cargo chef cook so rustflags apply to dependency builds; removes ARG/ENV RUSTFLAGS pair that would have silently overridden config.toml settings — though this removes external flag customisation via build-args. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Docker build context] -->|".dockerignore: !.cargo/"| B[includes .cargo/config.toml]
subgraph planner [planner stage]
C["COPY --exclude=.git --exclude=target . .\n(includes .cargo/)"]
D[cargo chef prepare → recipe.json]
C --> D
end
subgraph builder [builder stage]
E[COPY recipe.json]
F["COPY .cargo/ .cargo/\n(rustflags: -Ctarget-cpu=x86-64-v3)"]
G["cargo chef cook\n(deps compiled w/ AVX2/BMI2 flags)"]
H["COPY --exclude=target . .\n(full source)"]
I["cargo build --locked\n(reuses v3-flagged dep cache)"]
J[cp ethlambda → /app/ethlambda]
E --> F --> G --> H --> I --> J
end
subgraph runtime [runtime stage / ubuntu]
K[COPY ethlambda → /usr/local/bin]
L[ENTRYPOINT ethlambda]
K --> L
end
B --> planner
planner --> builder
builder --> runtime
Prompt To Fix All With AI
This is a comment left during a code review.
Path: .cargo/config.toml
Line: 4
Comment:
**`pclmulqdq` not guaranteed by x86-64-v3**
`+pclmulqdq` is not part of the official x86-64-v3 microarchitecture level (which defines: avx, avx2, bmi1, bmi2, f16c, fma, lzcnt, movbe, popcnt, sse4.2, xsave). Adding it via `-Ctarget-feature` raises the effective minimum CPU requirement slightly beyond what the v3 label advertises. In practice this is safe — pclmulqdq is present on all Intel Westmere (2010+) and AMD Bulldozer (2011+) chips, so every v3-capable CPU has it — but it's worth knowing the binary is technically targeting a stricter subset than "x86-64-v3".
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: Dockerfile
Line: 23-29
Comment:
**`RUSTFLAGS` build-arg removed — external override no longer possible**
Dropping `ARG RUSTFLAGS` removes the ability to pass different compiler flags at image-build time without editing `.cargo/config.toml`. Previously a caller could do `docker build --build-arg RUSTFLAGS="-Ctarget-cpu=x86-64-v2"` to produce a more portable image for a specific deployment. If any CI job or `make` target relied on `--build-arg RUSTFLAGS=...`, it will now silently be ignored (the arg just doesn't exist). Consider documenting that `.cargo/config.toml` is the intended override point going forward.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "build: compile docker image for x86-64-v..." | Re-trigger Greptile
| # Extra Cargo flags | ||
| ARG RUSTFLAGS="" | ||
| ENV RUSTFLAGS="$RUSTFLAGS" | ||
|
|
There was a problem hiding this comment.
This was removed since setting an empty RUSTFLAGS would discard the cargo config
Summary
Switch the release Docker image to the x86-64-v3 microarchitecture level so the binary uses AVX2, BMI1/2, LZCNT, and PCLMULQDQ. Any host from Haswell (2013) / Zen+ (2018) onward supports this.
On a Skylake-SP server, over a 400-slot devnet:
unstableunstable(default x86-64)-Ctarget-cpu=native-Ctarget-cpu=x86-64-v3(this PR)v3 beats
nativeby ~15% on this CPU because aggressive AVX-512 use on Skylake-SP triggers core downclocking — staying on AVX2 keeps the clock higher. v3 is also portable (native binaries won't run on most non-SP Intel client CPUs or older AMD parts).The config was copied from the
ethrexrepo: https://github.com/lambdaclass/ethrex/blob/1a2ec50ae6f99dd91046440f7e54e39cfcc01687/.cargo/config.tomlTwo Docker plumbing fixes included
Without these, the
.cargo/config.tomltarget.rustflagssetting is silently ignored:COPY .cargo/ .cargo/beforecargo chef cook— otherwise dependency builds emit with default flags, and the finalcargo buildreuses the cached deps rather than rebuilding with the requested CPU features. Verified: without this fix, the resulting binary was byte-identical to the default-flag build (zero AVX2/BMI2 usage).ARG RUSTFLAGS=""/ENV RUSTFLAGS="$RUSTFLAGS"pair. An emptyRUSTFLAGSenv var overridestarget.<triple>.rustflagsfrom.cargo/config.toml(cargo precedence rule: env wins over config). With the old Dockerfile, any build that didn't pass--build-arg RUSTFLAGS=...would silently drop target-cpu/target-feature selections.Instruction count diff (
objdump -d | grep ymm/zmm/bzhi/lzcnt):ymm(AVX2)zmm(AVX-512)bzhi(BMI2)lzcntpclmulqdq