Skip to content

deps: trim alloy to used features to cut build time#85

Open
koko1123 wants to merge 3 commits into
mainfrom
koko/beaconator-trim-alloy-features
Open

deps: trim alloy to used features to cut build time#85
koko1123 wants to merge 3 commits into
mainfrom
koko/beaconator-trim-alloy-features

Conversation

@koko1123

@koko1123 koko1123 commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Why

alloy is pulled in with the full meta-feature, which enables far more than this service uses. Every unused feature is extra crates to compile on each cold build and on every CI test-job compile.

Usage evidence in the codebase:

  • Transport: connect_http only — zero ws/ipc/pubsub.
  • Signers: PrivateKeySigner (local) + AwsSigner (KMS) only — zero keystore/mnemonic/ledger/trezor.
  • Anvil (tests): driven through generic raw_request("anvil_setBalance", ...), not the typed AnvilApi, so provider-anvil-api isn't needed.

What

Replace full with the minimal set actually used:

# before
alloy = { version = "2.1", features = ["full", "node-bindings", "signer-aws"] }
# after
alloy = { version = "2.1", features = ["essentials", "consensus", "eips", "network", "rlp", "k256", "node-bindings", "signer-aws"] }

essentials = contract + provider-http + rpc-types + signer-local, which covers the sol! contracts, the HTTP provider/fillers, and the local signer. This drops the kzg feature, the ws/ipc/pubsub transports, and the trace/txpool/debug/anvil provider RPC APIs.

Cargo.lock is gitignored in this repo, so this is a Cargo.toml-only change; the lockfile that CI/Docker regenerate resolves to the trimmed set.

Verified locally

  • cargo build --all-targets — clean (exit 0), so lib + both bins + the full test tree compile against the reduced feature set.
  • cargo test unit_tests200 passed, 0 failed (12 Redis-dependent ignored).
  • Crate count 596 -> 575 (-21). Dropped: tokio-tungstenite, tungstenite, interprocess, alloy-pubsub, alloy-transport-ws, alloy-transport-ipc, alloy-rpc-types-{trace,txpool,debug}, plus the kzg wrapper.

Honest scope

  • c-kzg stays — it comes in transitively via alloy-consensus/eips (needed for transaction types), not the kzg feature, so the heavy C build is not shed here.
  • alloy-rpc-types-anvil stays because node-bindings (kept, for spawning Anvil in tests) depends on it.
  • So this trims 21 Rust crates and the ws/ipc/pubsub stacks — a modest, permanent, zero-risk reduction — not the c-kzg C compile.

Independent of #84 (cargo-chef + shared rust-cache); both target main and touch different files.

Summary by CodeRabbit

  • Chores
    • Streamlined the blockchain integration to use a narrower set of protocol and cryptography capabilities, intentionally avoiding unused transports and RPC APIs.
    • Improved build/output tuning for smaller release artifacts and more compact debug information.
    • Ensured dependency locking is committed to support more reproducible and stable build caching.
    • No user-facing functionality or behavior changes are expected.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ca66b547-4b56-4eb0-9ba2-133b72f31c54

📥 Commits

Reviewing files that changed from the base of the PR and between 40ee76f and 21ae80f.

📒 Files selected for processing (1)
  • Cargo.toml
🚧 Files skipped from review as they are similar to previous changes (1)
  • Cargo.toml

📝 Walkthrough

Walkthrough

The Alloy dependency now uses selected features instead of full. Cargo build profiles limit debug data and strip release binaries, and Cargo.lock is no longer ignored.

Changes

Build configuration

Layer / File(s) Summary
Configure Alloy features
Cargo.toml
The alloy dependency uses explicit feature modules while retaining node bindings and AWS signer support.
Configure build reproducibility
Cargo.toml, .gitignore
Development and release profiles are configured, and comments document committed Cargo.lock tracking.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: narrowing Alloy features to reduce build time.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch koko/beaconator-trim-alloy-features

Comment @coderabbitai help to get the list of available commands.

…apis)

The service uses only the HTTP provider and local/AWS signers, so alloy's broad
'full' meta-feature is over-provisioned. Replace it with the minimal set actually
used; drops 21 crates (596->575) including the ws/ipc/pubsub transport stacks and
the trace/txpool/debug rpc-types. Verified: all targets compile, 200 unit tests pass.
@koko1123
koko1123 force-pushed the koko/beaconator-trim-alloy-features branch from a80a5ab to f6353cc Compare July 18, 2026 23:01
Un-ignore and commit Cargo.lock so image builds are reproducible and cargo-chef
gets a stable dependency-cache key. Add [profile.dev] debug=line-tables-only
(faster test-job compiles, smaller CI cache) and [profile.release] strip=true
(195MB image, down from 209MB).
@koko1123

Copy link
Copy Markdown
Collaborator Author

Expanded per review: added a build-config commit on top of the alloy trim.

  • Commit Cargo.lock (un-ignored) — reproducible image builds + a stable cargo-chef dependency-cache key.
  • [profile.dev] debug = "line-tables-only" — faster test-job compiles, smaller CI cache (all test jobs build in dev/test profile); backtraces keep file:line.
  • [profile.release] strip = true — image 209MB -> 195MB.

Verified locally: full docker build exit 0 (195MB), all targets compile, 200 unit tests pass. Left out of this PR deliberately: mold/lld linker (needs toolchain install + interacts with the -D warnings rustflags) and CI-infra caching (sccache/ECR buildcache) — those are separate PRs.

The service is I/O-bound (RPC/Redis/signing), so opt-level 3 buys no measurable
runtime win. Dropping to 2 cuts the release/image compile ~27% (26.5s -> 19.4s
crate recompile locally, more on the CI runner).
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