Skip to content

Conversation

@delino
Copy link
Contributor

@delino delino bot commented Jan 26, 2026

Description:

This PR systematically disables default features across all dependencies in the SWC repository to reduce binary size. This is a retry of PR #11208 rebased onto the current main branch.

The binary size gain from disabling unnecessary default features is significant - the original PR reported 422.37500KB reduction for @swc/core.

Note that removing a feature flag may break the build of downstream crates, so this should be marked as a breaking change for modified crates.


Changes

  • Add default-features = false to nearly every dependency in workspace and crate Cargo.toml files
  • Explicitly enable only the features that are actually needed
  • Update Cargo.lock to reflect the reduced dependency tree

Special Features Added

Some dependencies require specific features to function properly:

  • once_cell: ["std"]
  • pretty_assertions: ["std"]
  • serde_json: ["alloc"]
  • rustc-hash: ["std"]
  • regress: ["std", "backend-pikevm"]
  • flate2: ["rust_backend"]
  • lexical: ["parse"]
  • anyhow: ["std"]
  • clap: ["std"] where used
  • codspeed-criterion-compat: keeps default-features = true

Impact

By disabling default features, this PR eliminates unnecessary transitive dependencies that were previously pulled in automatically, significantly reducing the final binary size.


TODOs

  • Verify all tests pass in CI
  • Check for any missing features that may need to be added
  • Verify binary size reduction matches expectations

Related: #11208

This PR systematically disables default features across all dependencies in the SWC repository to reduce binary size, following the approach from PR #11208.

Key changes:
- Add `default-features = false` to nearly every dependency
- Explicitly enable only the features that are actually needed
- Special features added:
  - once_cell: ["std"]
  - pretty_assertions: ["std"]
  - serde_json: ["alloc"]
  - rustc-hash: ["std"]
  - regress: ["std", "backend-pikevm"]
  - flate2: ["rust_backend"]
  - lexical: ["parse"]
  - codspeed-criterion-compat: keeps default-features = true
  - anyhow: ["std"]
  - clap: ["std"] where used

This transformation significantly reduces binary size by eliminating unnecessary transitive dependencies that were previously pulled in automatically.

Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
@CLAassistant
Copy link

CLAassistant commented Jan 26, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ kdy1
❌ github-actions[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@changeset-bot
Copy link

changeset-bot bot commented Jan 26, 2026

⚠️ No Changeset found

Latest commit: 35ca992

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@socket-security
Copy link

socket-security bot commented Jan 26, 2026

No dependency changes detected. Learn more about Socket for GitHub.

👍 No dependency changes detected in pull request

kdy1 and others added 9 commits January 26, 2026 14:57
Add cbor4ii, dragonbox_ecma, getrandom, lightningcss, and owo-colors
to workspace dependencies that were accidentally removed during the
default-features refactoring.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add getrandom to cargo-shear ignored list (used for wasm builds)
- Enable serde-impl feature for swc_ecma_transforms_react dependency
  in swc_ecma_transforms_typescript (required for serde derive)
- Update wasmtime and wasi-common from v35 to v38 to fix security
  vulnerability RUSTSEC-2025-0118

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The serde crate needs the 'std' feature for String deserialization
support. Without it, hstr and other crates fail to compile because
String::deserialize is not available.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Several crates require std or other features to function:
- kstring requires 'std' feature
- tracing requires 'std' and 'attributes' features for #[instrument]
- base64 requires 'std' feature for encode/decode methods

Co-Authored-By: Claude Opus 4.5 <[email protected]>
…, quote

- rand requires 'std' and 'std_rng' for thread_rng and sample_string
- allocator-api2 requires 'std' for Global allocator
- syn requires default features for Clone impls and proc-macro support
- proc-macro2 and quote require 'proc-macro' feature

Co-Authored-By: Claude Opus 4.5 <[email protected]>
petgraph requires these features for GraphMap and StableGraph types
which are used by the bundler crate.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
lexical requires std, parse-integers, and parse-floats features for
Error, Result, ParseOptions, and FromLexical types.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add fmt feature to tracing-subscriber for FmtSubscriber support
- Add clap to workspace deps with std and derive features
- Update generate-code and swc-releaser to use workspace clap

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Required for with_env_filter() in testing crate

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 26, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing devbird/retry-pr-11208 (35ca992) with main (a54eb0e)

Summary

✅ 184 untouched benchmarks

kdy1 and others added 6 commits January 26, 2026 16:28
- Add std feature to serde_json for from_reader support
- Add ansi feature to tracing-subscriber for pretty() method

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Add missing typescript feature to swc_ecma_parser dependencies that
had default-features = false but needed TypeScript syntax support.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
IndexMap requires the std feature to have a default hasher type and
the new() method.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Add std feature to backtrace for Backtrace type
- Add serde-impl feature to swc_estree_ast in swc_estree_compat

Co-Authored-By: Claude Opus 4.5 <[email protected]>
path_clean::clean returns String, but Input::File expects PathBuf

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions
Copy link
Contributor

github-actions bot commented Jan 26, 2026

Binary Sizes

File Size
swc.linux-x64-gnu.node 27M (28119240 bytes)

Commit: 443ed57

Wasmer requires at least one compiler backend to function

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@kdy1 kdy1 added this to the Planned milestone Jan 26, 2026
kdy1 and others added 3 commits January 26, 2026 17:51
- Add derive feature to shrink-to-fit for ShrinkToFit derive macro
- Enable default features for wasmer-wasix (complex crate with many required features)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Default features bring in webpki-roots with CDLA-Permissive-2.0 license
which is not allowed by the project's license policy.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Revert to original default-features = false as the PR intended.
The swc_plugin_backend_wasmer crate uses its own feature flags.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants