Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: set default SWC minimizer passes to 2 to reduce bundle size #8853

Merged
merged 3 commits into from
Dec 26, 2024

Conversation

chenjiahan
Copy link
Member

@chenjiahan chenjiahan commented Dec 26, 2024

What is passes

The maximum number of times to run compress. In some cases, more than one pass leads to further compressed code. Keep in mind more passes will take more time.

Why increase passes

Considering that Rspack is already quite fast, we should allocate more budget for bundle size optimization.

Bundle Size:

  • Increasing passes can reduce output size by 0-6%, with optimization results depending on user code
  • Optimization effects are similar between 2 and 3 passes, with diminishing returns beyond 3 passes

Build Time:

  • For simple cases, increasing passes adds 3-5% to overall build time
  • For complex cases, increasing passes adds 10-20% to overall build time

Setting passes to 2 by default offers a good balance of build performance and bundle size optimization.

Test case 1

output: {
  minify: {
    jsOptions: {
      minimizerOptions: {
        compress: {
          passes: Number(process.env.PASSES) ?? 1,
        },
      },
    },
  },
},
performance: {
  chunkSplit: {
    strategy: "all-in-one",
  },
},
  • Build time:
hyperfine --warmup 2 --runs 5 'PASSES=1 node --run rsbuild' 'PASSES=2 node --run rsbuild' 'PASSES=3 node --run rsbuild' 'PASSES=4 node --run rsbuild'

Benchmark 1: PASSES=1 node --run rsbuild
  Time (mean ± σ):      1.581 s ±  0.018 s    [User: 2.705 s, System: 0.698 s]
  Range (min … max):    1.557 s …  1.604 s    5 runs
 
Benchmark 2: PASSES=2 node --run rsbuild
  Time (mean ± σ):      1.716 s ±  0.030 s    [User: 2.925 s, System: 0.786 s]
  Range (min … max):    1.683 s …  1.762 s    5 runs
 
Benchmark 3: PASSES=3 node --run rsbuild
  Time (mean ± σ):      1.870 s ±  0.067 s    [User: 3.126 s, System: 0.837 s]
  Range (min … max):    1.794 s …  1.962 s    5 runs
 
Benchmark 4: PASSES=4 node --run rsbuild
  Time (mean ± σ):      1.998 s ±  0.042 s    [User: 3.323 s, System: 0.894 s]
  Range (min … max):    1.935 s …  2.045 s    5 runs
 
Summary
  PASSES=1 node --run rsbuild ran
    1.09 ± 0.02 times faster than PASSES=2 node --run rsbuild
    1.18 ± 0.04 times faster than PASSES=3 node --run rsbuild
    1.26 ± 0.03 times faster than PASSES=4 node --run rsbuild
  • Bundle size:
[passes 1]
Total: 2561.6 kB (gzip: 685.3 kB)

[passes 2] 124.6kB less than the previous value
Total: 2437.0 kB (gzip: 650.8 kB)

[passes 3] 29.2kB less than the previous value
Total: 2407.8 kB (gzip: 642.1 kB)

[passes 4] 8.5kB less than the previous value
Total: 2399.3 kB (gzip: 639.3 kB)

Test case 2

  output: {
    minify: {
      jsOptions: {
        minimizerOptions: {
          compress: {
            passes: Number(process.env.PASSES) ?? 1,
          },
        },
      },
    },
  },
  • Build time:
hyperfine --warmup 2 --runs 5 'PASSES=1 node --run build' 'PASSES=2 node --run build' 'PASSES=3 node --run build' 'PASSES=4 node --run build'

Benchmark 1: PASSES=1 node --run build
  Time (mean ± σ):      3.399 s ±  0.165 s    [User: 8.534 s, System: 2.053 s]
  Range (min … max):    3.241 s …  3.654 s    5 runs
 
Benchmark 2: PASSES=2 node --run build
  Time (mean ± σ):      3.539 s ±  0.112 s    [User: 9.080 s, System: 2.199 s]
  Range (min … max):    3.399 s …  3.699 s    5 runs
 
Benchmark 3: PASSES=3 node --run build
  Time (mean ± σ):      3.518 s ±  0.026 s    [User: 9.603 s, System: 2.328 s]
  Range (min … max):    3.491 s …  3.555 s    5 runs
 
Benchmark 4: PASSES=4 node --run build
  Time (mean ± σ):      3.712 s ±  0.114 s    [User: 9.932 s, System: 2.442 s]
  Range (min … max):    3.594 s …  3.885 s    5 runs
 
Summary
  PASSES=1 node --run build ran
    1.04 ± 0.05 times faster than PASSES=3 node --run build
    1.04 ± 0.06 times faster than PASSES=2 node --run build
    1.09 ± 0.06 times faster than PASSES=4 node --run build
  • Bundle size:
[passes 1]
Total: 8950.5 kB (gzip: 2489.8 kB)

[passes 2] 14.3kB less than the previous value
Total: 8936.2 kB (gzip: 2485.5 kB)

[passes 3] 5.7kB less than the previous value
Total: 8930.5 kB (gzip: 2483.5 kB)

[passes 4] 0.4kB less than the previous value
Total: 8930.1 kB (gzip: 2483.3 kB)

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: performance release: performance related release(mr only) labels Dec 26, 2024
Copy link

netlify bot commented Dec 26, 2024

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit f92f27c
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/676d23bd84e3c000083e696b

@chenjiahan chenjiahan changed the title perf: increase default SWC minimizer passes to reduce bundle size perf: set default SWC minimizer passes to 2 to reduce bundle size Dec 26, 2024
hardfist
hardfist previously approved these changes Dec 26, 2024
@chenjiahan chenjiahan changed the title perf: set default SWC minimizer passes to 2 to reduce bundle size feat: set default SWC minimizer passes to 2 to reduce bundle size Dec 26, 2024
@github-actions github-actions bot added release: feature release: feature related release(mr only) and removed release: performance release: performance related release(mr only) labels Dec 26, 2024
Copy link

codspeed-hq bot commented Dec 26, 2024

CodSpeed Performance Report

Merging #8853 will not alter performance

Comparing passes_default_value_1226 (f92f27c) with main (7707956)

Summary

✅ 3 untouched benchmarks

@chenjiahan chenjiahan requested a review from hardfist December 26, 2024 10:37
@hardfist hardfist merged commit 97dd0f8 into main Dec 26, 2024
32 checks passed
@hardfist hardfist deleted the passes_default_value_1226 branch December 26, 2024 10:43
@chenjiahan chenjiahan self-assigned this Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants