Skip to content

perf: Disable all unnecessary default-features#11208

Draft
kdy1 wants to merge 38 commits intomainfrom
kdy1/size-check
Draft

perf: Disable all unnecessary default-features#11208
kdy1 wants to merge 38 commits intomainfrom
kdy1/size-check

Conversation

@kdy1
Copy link
Copy Markdown
Member

@kdy1 kdy1 commented Oct 30, 2025

Description:

This is to drop dependencies that is not strictly required. The binary size gain of this PR for @swc/core is 422.37500KB

Note that removing a feature flag may break the build of the downstram crates, so I'll mark this as a breaking change of modified crates.


TODOs

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Oct 30, 2025

⚠️ No Changeset found

Latest commit: 18aeca8

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

@kdy1 kdy1 added this to the Planned milestone Oct 30, 2025
@kdy1 kdy1 changed the title perf: Disable perf: Disable all unnecessary default-features Oct 30, 2025
@claude

This comment has been minimized.

…tributes feature

- Update swc_atoms from 8.0.2 to 9.0.0
- Update swc_common from 16.0.0 to 18.0.1
- Update swc_ecma_ast from 17.0.0 to 20.0.1
- Update swc_ecma_transforms_base from 29.0.0 to 36.0.1
- Update swc_ecma_utils from 23.0.0 to 26.0.1
- Update swc_ecma_visit from 17.0.0 to 20.0.0
- Add tracing 'attributes' feature required for #[swc_trace] macro

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
@kdy1
Copy link
Copy Markdown
Member Author

kdy1 commented Feb 2, 2026

@claude fix CI

@claude

This comment has been minimized.

…r swc_common

- hstr: Add `std` feature to serde dependency to enable String::deserialize
- swc_common: Add `attributes` feature to tracing dependency to enable #[instrument] macro

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
@kdy1 kdy1 marked this pull request as ready for review February 2, 2026 12:20
@kdy1 kdy1 requested a review from a team as a code owner February 2, 2026 12:20
Copilot AI review requested due to automatic review settings February 2, 2026 12:20
@kdy1 kdy1 requested review from a team as code owners February 2, 2026 12:20
@kdy1 kdy1 marked this pull request as draft February 2, 2026 12:20
@kdy1
Copy link
Copy Markdown
Member Author

kdy1 commented Feb 2, 2026

@claude Fix CI

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 2, 2026

Claude finished @kdy1's task in 2m 14s —— View job


Fixing CI

  • Check CI status and identify failures
  • Analyze failing jobs
  • Fix the issues
  • Push fixes

Fixed issues:

  1. swc_common: Added derive feature to shrink-to-fit dependency - required for the ShrinkToFit derive macro
  2. swc_core: Added serde-impl feature to swc_ecma_transforms_react dependency - required for serde support in react transforms

Pushed commit e5fffc45f
| Branch

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 2, 2026

PR Review: perf: Disable all unnecessary default-features

Overview

This PR aims to reduce binary size by disabling unnecessary default features across all dependencies. The reported binary size reduction of ~422KB for @swc/core is significant. However, there are several issues that need to be addressed.


🔴 Critical Issues (Blocking)

1. CI Build Failures - Missing petgraph::graphmap Feature

The build is currently failing with:

error[E0432]: unresolved import `petgraph::prelude::GraphMap`
error: could not compile `swc_ecma_transforms_optimization` (lib) due to 1 previous error

The issue is in Cargo.toml:

petgraph = { version = "0.7.1", default-features = false }

This disables the graphmap feature, but swc_ecma_transforms_optimization/src/simplify/dce/mod.rs:4 imports:

use petgraph::{algo::tarjan_scc, prelude::GraphMap, Directed, Direction::Incoming};

Fix: Add the required features:

petgraph = { version = "0.7.1", default-features = false, features = ["graphmap"] }

And in crates/swc_ecma_transforms_optimization/Cargo.toml:

petgraph = { workspace = true, default-features = false, features = ["graphmap"] }

🟡 Code Quality Observations

2. New swc_ecma_compiler Crate

The new swc_ecma_compiler crate (855 lines in lib.rs) adds substantial new functionality. Some observations:

Positives:

  • Well-structured with clear separation of ES2020, ES2021, ES2022 transformations
  • Good use of bitflags for feature selection
  • Proper visitor pattern implementation

Concerns:

  • features.rs:8 defines OPTIONAL_CHAINING feature flag but it doesn't appear to be implemented in any transformation code in this PR. Is this intentional for future use?
  • The crate lacks unit tests. Consider adding tests for the transformations (especially for the complex private_in_object and nullish_coalescing transformations).

3. Wtf8Atom Serialization (crates/hstr/src/wtf8_atom.rs)

The new serialization/deserialization logic for handling unpaired surrogates looks well-thought-out and has comprehensive test coverage. The fix for issue #11214 (backslash handling) is correctly addressed.


🟢 Performance Observations

The approach of systematically disabling default-features across all workspace dependencies is sound for binary size reduction. The explicit re-enabling of necessary features (e.g., lexical = { ..., features = ["std", "parse-floats", "parse-integers"] }) shows careful attention to maintaining functionality.


📋 Recommendations

  1. Fix the petgraph feature issue - This is blocking CI.

  2. Consider feature documentation - Since this PR marks many crates as default-features = false, downstream users may need to explicitly enable features. Consider documenting which features are essential for common use cases.

  3. Add tests for swc_ecma_compiler - The new crate implements complex ECMAScript transformations but lacks dedicated tests.

  4. Verify the rspack issue - The TODO mentions checking [Bug]: ProgressPlugin containing non-ASCII characters cannot clear the screen web-infra-dev/rspack#10988 (comment) - ensure this is verified before merging.


Summary

The PR's goal of reducing binary size through careful feature management is valuable. However, the build is currently broken due to missing petgraph features. Once that's fixed and CI passes, this should be ready for final review.

Estimated Impact:

  • Binary size reduction: ✅ ~422KB (significant)
  • Breaking changes: ⚠️ Yes (as noted in PR description - downstream crates may need feature adjustments)
  • Test coverage: 🔶 Existing tests for Wtf8Atom, missing for new swc_ecma_compiler crate

…r swc_common

- Add `derive` feature to shrink-to-fit dependency in swc_common
- Add `serde-impl` feature to swc_ecma_transforms_react in swc_core

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR systematically disables default features across hundreds of dependencies in the SWC monorepo to reduce binary size by ~422KB. The changes span workspace-level configuration and individual crate manifests.

Changes:

  • Workspace dependencies now specify default-features = false
  • Necessary features are explicitly re-enabled (e.g., std, alloc for serde_json)
  • New swc_ecma_compiler crate added
  • Test code gated with #[cfg(feature = "serde")]

Reviewed changes

Copilot reviewed 146 out of 147 changed files in this pull request and generated 5 comments.

File Description
Cargo.toml Workspace-level dependency defaults disabled with explicit feature re-enabling
crates/*/Cargo.toml ~100+ crates updated to disable default features
crates/swc_ecma_compiler/* New crate for ES compatibility layer
crates/hstr/src/wtf8_atom.rs Added feature gates for serde-dependent tests

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

js-sys = { version = "0.3.77", default-features = false }
jsonc-parser = { version = "0.26.2", default-features = false }
kstring = { version = "2.0.0", default-features = false }
lazy_static = { version = "1.4.0", default-features = false }
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workspace lexical dependency adds explicit features ["std", "parse-floats", "parse-integers"] when disabling default features. This is good practice as lexical requires these for basic functionality. Consider documenting why these specific features are needed to help future maintainers understand the requirement.

Suggested change
lazy_static = { version = "1.4.0", default-features = false }
lazy_static = { version = "1.4.0", default-features = false }
# lexical's default features are disabled; `std`, `parse-floats`, and `parse-integers`
# are explicitly enabled because they are required for the crate's basic number
# parsing functionality used across this workspace.

Copilot uses AI. Check for mistakes.
st-map = { version = "0.2.0", default-features = false }
string_cache = { version = "0.8.7", default-features = false }
swc_sourcemap = { version = "9.3.4", default-features = false }
syn = { version = "2", default-features = false, features = ["derive", "parsing", "printing", "clone-impls", "proc-macro"] }
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syn workspace dependency uses features = ["derive", "parsing", "printing", "clone-impls", "proc-macro"] with default-features = false. However, individual crates using syn (like testing_macros, various codegen_macros crates) specify different feature sets without proc-macro. This could cause issues if the workspace default features don't align with what the crates actually need. Verify that all syn usages have the correct features explicitly listed.

Suggested change
syn = { version = "2", default-features = false, features = ["derive", "parsing", "printing", "clone-impls", "proc-macro"] }
syn = { version = "2", default-features = false }

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +24
anyhow = { workspace = true, default-features = false }
glob = { workspace = true, default-features = false }
once_cell = { workspace = true, default-features = false }
proc-macro2 = { workspace = true, default-features = false }
quote = { workspace = true, default-features = false }
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proc-macro2, quote, and syn crates typically require the proc-macro feature to be enabled when used in proc-macro crates. Disabling default features without explicitly enabling necessary features like proc-macro may cause compilation failures. Please verify that these dependencies build correctly without default features, or add the required features explicitly.

Copilot uses AI. Check for mistakes.
bumpalo = { workspace = true, features = ["allocator-api2"] }
hashbrown = { workspace = true, optional = true }
rustc-hash = { workspace = true }
allocator-api2 = { workspace = true, default-features = true }
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The allocator-api2 crate has default-features = true which is inconsistent with the PR's goal of disabling default features. This should likely be default-features = false for consistency, unless there's a specific reason to keep defaults enabled for this dependency.

Suggested change
allocator-api2 = { workspace = true, default-features = true }
allocator-api2 = { workspace = true, default-features = false }

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +40
compact_str = { workspace = true, default-features = true }
criterion = { workspace = true, default-features = true }
kstring = { workspace = true, default-features = true, features = ["std"] }
num_cpus = { workspace = true, default-features = true }
par-iter = { workspace = true, default-features = true }
rand = { workspace = true, default-features = true }
serde_json = { workspace = true, default-features = true }
smartstring = { workspace = true, default-features = true }
smol_str = { workspace = true, default-features = true }
string_cache = { workspace = true, default-features = true }
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workspace configuration sets default-features = true for several dev-dependencies (codspeed-criterion-compat, criterion, compact_str, kstring, etc.) while the PR aims to disable default features. This inconsistency should be reviewed - either these need defaults enabled for a specific reason, or they should be set to false for consistency with the PR's goals.

Suggested change
compact_str = { workspace = true, default-features = true }
criterion = { workspace = true, default-features = true }
kstring = { workspace = true, default-features = true, features = ["std"] }
num_cpus = { workspace = true, default-features = true }
par-iter = { workspace = true, default-features = true }
rand = { workspace = true, default-features = true }
serde_json = { workspace = true, default-features = true }
smartstring = { workspace = true, default-features = true }
smol_str = { workspace = true, default-features = true }
string_cache = { workspace = true, default-features = true }
compact_str = { workspace = true, default-features = false }
criterion = { workspace = true, default-features = false }
kstring = { workspace = true, default-features = false, features = ["std"] }
num_cpus = { workspace = true, default-features = false }
par-iter = { workspace = true, default-features = false }
rand = { workspace = true, default-features = false }
serde_json = { workspace = true, default-features = false }
smartstring = { workspace = true, default-features = false }
smol_str = { workspace = true, default-features = false }
string_cache = { workspace = true, default-features = false }

Copilot uses AI. Check for mistakes.
@kdy1
Copy link
Copy Markdown
Member Author

kdy1 commented Feb 2, 2026

@claude fix ci

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 2, 2026

Claude finished @kdy1's task in 8m 37s —— View job


Fixing CI

  • Check CI status and identify failures
  • Analyze failing jobs
  • Fix the issues
  • Verify local build
  • Push fixes

Fixed issues:

  1. swc_ecma_transforms/Cargo.toml: Added serde-impl feature to swc_ecma_transforms_react - required for serde imports in jsx/mod.rs and refresh/options.rs
  2. testing/Cargo.toml: Added std, fmt, ansi features to tracing-subscriber and std to tracing - required for FmtSubscriber, set_default, and .pretty()
  3. swc_config/Cargo.toml: Added std feature to anyhow - required for Context trait
  4. Cargo.toml (workspace): Added std, unicode features to regex - required for std::error::Error impl
  5. swc_ecma_transforms_optimization/Cargo.toml: Added graphmap feature to petgraph - required for GraphMap import
  6. swc_ecma_transforms_react/Cargo.toml: Added alloc feature to base64 - required for .encode() method
  7. swc_ecma_preset_env/Cargo.toml: Added std feature to anyhow and rustc-hash in build-dependencies - required for FxHashSet
  8. swc_ecma_minifier/Cargo.toml: Added std feature to tracing - required for set_default function
  9. swc/Cargo.toml: Added std feature to anyhow and base64 - required for Context trait and DecodeError error handling

Pushed commit 0c7f50ee8 | Branch

- swc_ecma_transforms: Add serde-impl feature to swc_ecma_transforms_react
- testing: Add std, fmt, ansi features to tracing-subscriber, std to tracing
- swc_config: Add std feature to anyhow for Context trait
- Cargo.toml: Add std, unicode features to regex for std::error::Error impl
- swc_ecma_transforms_optimization: Add graphmap feature to petgraph
- swc_ecma_transforms_react: Add alloc feature to base64 for encode method
- swc_ecma_preset_env: Add std to anyhow and rustc-hash in build-deps
- swc_ecma_minifier: Add std to tracing for set_default function
- swc: Add std to anyhow and base64 for error handling

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
@socket-security
Copy link
Copy Markdown

socket-security bot commented Feb 2, 2026

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

👍 No dependency changes detected in pull request

@kdy1
Copy link
Copy Markdown
Member Author

kdy1 commented Feb 2, 2026

@claude fix ci

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 2, 2026

Claude finished @kdy1's task in 5m 29s —— View job


Fixing CI

  • Check CI status and identify failures
  • Analyze failing jobs
  • Fix the issues
  • Verify local build
  • Push fixes

Fixed issues:

  1. Cargo.toml (workspace): Added alloc feature to hex - required for hex::encode
  2. Cargo.toml (workspace): Added std feature to indexmap - required for IndexMap::new()
  3. swc_ts_fast_strip/Cargo.toml: Added serde-impl feature to swc_ecma_transforms_react - required for serde imports in jsx/mod.rs and refresh/options.rs

Pushed commit af2ff3ad5 | Branch

- hex: Add alloc feature required for hex::encode
- indexmap: Add std feature required for IndexMap::new()
- swc_ts_fast_strip: Add serde-impl feature to swc_ecma_transforms_react

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
@kdy1
Copy link
Copy Markdown
Member Author

kdy1 commented Feb 3, 2026

@claude fix ci

@claude
Copy link
Copy Markdown
Contributor

claude bot commented Feb 3, 2026

Claude finished @kdy1's task in 4m 13s —— View job


Fixing CI

  • Check CI status and identify failures
  • Analyze failing jobs
  • Fix the issues
  • Push fixes

Fixed issues:

  1. Cargo.toml (workspace): Added std feature to base64 - required for encode and encode_string methods used in swc_compiler_base, swc_ecma_transforms_testing, and swc_ecma_transforms_react
  2. swc_ecma_transforms_react/Cargo.toml: Removed explicit features = ["alloc"] to inherit workspace's std feature for base64
  3. swc_ecma_transforms_typescript/Cargo.toml: Added serde-impl feature to swc_ecma_transforms_react dependency - required for serde imports in jsx/mod.rs and refresh/options.rs during benchmarks

Pushed commit 18aeca805 | View job | Branch

- Cargo.toml: Added `std` feature to `base64` - required for `encode` and
  `encode_string` methods used in swc_compiler_base and other crates
- swc_ecma_transforms_react: Removed explicit `features = ["alloc"]` to
  inherit workspace's `std` feature for base64
- swc_ecma_transforms_typescript: Added `serde-impl` feature to
  `swc_ecma_transforms_react` dependency - required for serde imports
  in jsx/mod.rs and refresh/options.rs during benchmarks

Co-authored-by: Donny/강동윤 <kdy1@users.noreply.github.com>
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Feb 3, 2026

CodSpeed Performance Report

Merging this PR will improve performance by 4.07%

Comparing kdy1/size-check (18aeca8) with main (3e63627)

Summary

⚡ 2 improved benchmarks
✅ 76 untouched benchmarks
⏩ 106 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
es/codegen/with-parser/large 1.2 ms 1.1 ms +3.21%
es/codegen/with-parser/colors 158.5 µs 152.3 µs +4.07%

Footnotes

  1. 106 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@kdy1
Copy link
Copy Markdown
Member Author

kdy1 commented Mar 7, 2026

@codex Review

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.

3 participants