Skip to content

feat(swc_es_parser): expand benchmark corpus without swc_ecma dependencies#11633

Merged
kdy1 merged 1 commit intomainfrom
kdy1/swc-es-parser-bench-parity
Mar 9, 2026
Merged

feat(swc_es_parser): expand benchmark corpus without swc_ecma dependencies#11633
kdy1 merged 1 commit intomainfrom
kdy1/swc-es-parser-bench-parity

Conversation

@kdy1
Copy link
Copy Markdown
Member

@kdy1 kdy1 commented Mar 8, 2026

Summary

  • expand swc_es_parser parser/lexer benchmarks from 2 fixtures to the 11-file corpus used by swc_ecma_parser benchmarks
  • localize benchmark fixtures under crates/swc_es_parser/benches/files and remove all swc_ecma_* path references from benchmark code
  • strengthen no_ecma_dependency coverage to also fail if benches/.rs references swc_ecma_ symbols

Verification

  • git submodule update --init --recursive
  • cargo bench -p swc_es_parser --bench parser --no-run
  • cargo bench -p swc_es_parser --bench lexer --no-run
  • cargo test -p swc_es_parser no_ecma_dependency
  • cargo test -p swc_es_parser --test no_ecma_dependency
  • cargo test -p swc_es_parser
  • cargo fmt --all
  • cargo clippy --all --all-targets -- -D warnings

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 8, 2026

⚠️ No Changeset found

Latest commit: a77dd3f

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 8, 2026

Binary Sizes

File Size
swc.linux-x64-gnu.node 28M (28744264 bytes)

Commit: 7fa6333

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 8, 2026

Merging this PR will not alter performance

✅ 200 untouched benchmarks
🆕 18 new benchmarks

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 es_parser/lexer/jquery N/A 4.6 ms N/A
🆕 es_parser/lexer/jquery-mobile N/A 6.7 ms N/A
🆕 es_parser/lexer/colors N/A 21 µs N/A
🆕 es_parser/lexer/backbone N/A 848.8 µs N/A
🆕 es_parser/bootstrap/underscore N/A 3.3 ms N/A
🆕 es_parser/bootstrap/typescript-js N/A 132.6 ms N/A
🆕 es_parser/lexer/mootools N/A 3.5 ms N/A
🆕 es_parser/lexer/three N/A 21.4 ms N/A
🆕 es_parser/bootstrap/mootools N/A 9 ms N/A
🆕 es_parser/bootstrap/three N/A 36.4 ms N/A
🆕 es_parser/bootstrap/backbone N/A 3.7 ms N/A
🆕 es_parser/bootstrap/jquery N/A 12.8 ms N/A
🆕 es_parser/bootstrap/yui N/A 4.1 ms N/A
🆕 es_parser/lexer/yui N/A 3.6 ms N/A
🆕 es_parser/bootstrap/colors N/A 68.8 µs N/A
🆕 es_parser/bootstrap/jquery-mobile N/A 12.7 ms N/A
🆕 es_parser/lexer/typescript-js N/A 110.9 ms N/A
🆕 es_parser/lexer/underscore N/A 734.2 µs N/A

Comparing kdy1/swc-es-parser-bench-parity (a77dd3f) with main (f70a4b7)

Open in CodSpeed

@kdy1 kdy1 marked this pull request as ready for review March 9, 2026 01:46
@kdy1 kdy1 requested a review from a team as a code owner March 9, 2026 01:46
Copilot AI review requested due to automatic review settings March 9, 2026 01:46
@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@kdy1 kdy1 merged commit ff3adef into main Mar 9, 2026
203 of 205 checks passed
@kdy1 kdy1 deleted the kdy1/swc-es-parser-bench-parity branch March 9, 2026 01:47
@github-actions github-actions Bot added this to the Planned milestone Mar 9, 2026
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Mar 9, 2026

PR Review: expand benchmark corpus without swc_ecma dependencies

Overall

Good goal — decoupling swc_es_parser benchmarks from swc_ecma_parser paths. The test coverage for the no-dependency invariant is a nice addition. A few items worth considering:

1. File duplication (~12 MB of identical files)

The 11 benchmark fixture files are byte-identical copies of the files already in crates/swc_ecma_parser/benches/files/. This doubles the storage for these fixtures in the repo. Since these are checked into git (not gitignored), every clone carries the extra weight.

Alternatives to consider:

  • Symlinksln -s ../../swc_ecma_parser/benches/files/*.js . would avoid duplication while keeping local paths. include_str! resolves symlinks fine. However, this would violate the "no swc_ecma references" invariant at the filesystem level, so it depends on how strictly that's meant.
  • Shared top-level benches/files/ directory that both crates reference.
  • Git LFS for these large JS fixtures (especially typescript.js at 171K lines).

If the intent is to keep the crates fully independent (so swc_ecma_parser could be removed someday), then the duplication is a reasonable trade-off — but it's worth documenting that rationale.

2. Benchmark naming inconsistency in parser.rs

The parser benchmark names use "es_parser/bootstrap/..." (e.g., es_parser/bootstrap/angular), while in swc_ecma_parser they use "es/parser/...". The "bootstrap" prefix is misleading — these are parser benchmarks, not bootstrap-related. The lexer benchmarks correctly use "es_parser/lexer/...".

Should be "es_parser/parser/..." for consistency with the lexer naming and with what these benchmarks actually measure.

3. Repetitive benchmark registration

Both lexer.rs and parser.rs have 11 nearly identical c.bench_function(...) blocks that differ only in name and file path. A helper like:

const BENCH_FILES: &[(&str, &str, Syntax)] = &[
    ("colors", include_str!("./files/colors.js"), Syntax::Es(EsSyntax::default())),
    // ...
];

for (name, src, syntax) in BENCH_FILES {
    c.bench_function(&format!("es_parser/lexer/{name}"), |b| {
        bench_lex(b, *syntax, src)
    });
}

This would reduce duplication and make adding future benchmarks easier. The swc_ecma_parser benchmarks have the same pattern, so this isn't a regression — just an improvement opportunity.

4. no_ecma_dependency test — contains_swc_ecma_reference is very broad

The new contains_swc_ecma_reference function matches on the substring "swc_ecma_" anywhere in the source. This could give false positives on:

  • Comments explaining the relationship to swc_ecma_parser
  • String literals in test assertions

The existing contains_swc_ecma_parser_import function is more precise. Consider making the new check slightly more targeted (e.g., excluding comments), or at least documenting that bench files shouldn't mention swc_ecma_* even in comments.

5. Minor nit

The colors.js benchmark in parser.rs was originally labeled with a comment // Copied from ratel-rust in the swc_ecma_parser version. That context is lost in the new file.

Summary

The core change is sound — expanding the benchmark corpus and removing cross-crate path dependencies. The main concern is the 12 MB of duplicated fixture files. The "bootstrap" naming in parser benchmarks should be fixed. Everything else is minor.

🤖 Generated with Claude Code

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 expands swc_es_parser’s Criterion benchmarks to use the same 11-file fixture corpus as swc_ecma_parser, while ensuring the swc_es_parser crate (including benches) does not reference the swc_ecma_* crate family.

Changes:

  • Expanded parser/lexer benchmarks from 2 fixtures to an 11-file corpus and switched include_str! paths to local benches/files.
  • Vendored benchmark fixture files under crates/swc_es_parser/benches/files.
  • Strengthened the no_ecma_dependency test to fail if any benches/*.rs contains a swc_ecma_ reference.

Reviewed changes

Copilot reviewed 6 out of 14 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/swc_es_parser/tests/no_ecma_dependency.rs Adds bench scanning to forbid swc_ecma_* references in benchmark Rust sources.
crates/swc_es_parser/benches/parser.rs Expands parser benchmark cases and switches fixtures to local ./files/* paths.
crates/swc_es_parser/benches/lexer.rs Expands lexer benchmark cases and switches fixtures to local ./files/* paths.
crates/swc_es_parser/benches/files/colors.js Adds local benchmark fixture (colors).
crates/swc_es_parser/benches/files/angular-1.2.5.js Adds local benchmark fixture (Angular).
crates/swc_es_parser/benches/files/backbone-1.1.0.js Adds local benchmark fixture (Backbone).
crates/swc_es_parser/benches/files/jquery-1.9.1.js Adds local benchmark fixture (jQuery).
crates/swc_es_parser/benches/files/jquery.mobile-1.4.2.js Adds local benchmark fixture (jQuery Mobile).
crates/swc_es_parser/benches/files/mootools-1.4.5.js Adds local benchmark fixture (MooTools).
crates/swc_es_parser/benches/files/underscore-1.5.2.js Adds local benchmark fixture (Underscore).
crates/swc_es_parser/benches/files/three-0.138.3.js Adds local benchmark fixture (three.js).
crates/swc_es_parser/benches/files/yui-3.12.0.js Adds local benchmark fixture (YUI).
crates/swc_es_parser/benches/files/cal.com.tsx Adds local benchmark fixture (TSX).
crates/swc_es_parser/benches/files/typescript.js Adds local benchmark fixture (TypeScript compiler JS).

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

You can also share your feedback on Copilot code review. Take the survey.

@github-actions github-actions Bot modified the milestones: Planned, 1.15.21 Mar 22, 2026
@swc-project swc-project locked as resolved and limited conversation to collaborators Apr 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants