Skip to content

fix(pack): compatWebpack treeshaking config#2684

Merged
xusd320 merged 3 commits into
nextfrom
fix-unused-exports
Mar 12, 2026
Merged

fix(pack): compatWebpack treeshaking config#2684
xusd320 merged 3 commits into
nextfrom
fix-unused-exports

Conversation

@fireairforce

Copy link
Copy Markdown
Member

Summary

Default value of webpack's unsedexports is true: https://webpack.js.org/configuration/optimization/#optimizationusedexports

It means even if it's undefined(user don't config), it will enable.

!!undefined === false in javascript, so in the default case utoopack will disable tree shaking(but webpack will enable).

Test Plan

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical compatibility issue within utoopack's Webpack optimization configuration. Previously, the system's boolean evaluation of undefined for usedExports inadvertently led to the disabling of tree-shaking features, contrary to Webpack's default behavior. The changes ensure that utoopack now correctly respects Webpack's default tree-shaking enablement when usedExports is not explicitly set to false, thereby improving bundle optimization.

Highlights

  • Webpack Tree-shaking Compatibility Fix: Addressed an issue where utoopack incorrectly disabled Webpack's tree-shaking features (treeShaking, removeUnusedExports, removeUnusedImports) when the usedExports configuration was undefined. The logic now correctly interprets undefined as enabling these features, aligning with Webpack's default behavior.
Changelog
  • packages/pack-shared/src/webpackCompat.ts
    • Introduced enableTreeShaking variable to accurately reflect Webpack's usedExports behavior.
    • Modified treeShaking, removeUnusedExports, and removeUnusedImports properties to use the new enableTreeShaking variable for correct conditional enablement.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Comment thread packages/pack-shared/src/webpackCompat.ts

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

The pull request refactors the compatOptimization function in packages/pack-shared/src/webpackCompat.ts by introducing a new constant enableTreeShaking derived from usedExports !== false. This constant is then consistently applied to the treeShaking, removeUnusedExports, and removeUnusedImports properties, improving code readability and maintainability.

Comment thread packages/pack-shared/src/webpackCompat.ts Outdated
Comment thread packages/pack-shared/src/webpackCompat.ts Outdated
Comment thread packages/pack-shared/src/webpackCompat.ts Outdated
@xusd320 xusd320 enabled auto-merge (squash) March 12, 2026 08:15
@github-actions

Copy link
Copy Markdown

📊 Performance Benchmark Report (with-antd)

Utoopack Performance Report (Intelligent)

Report ID: utoopack_performance_report_20260312_091457
Generated: 2026-03-12 09:14:57
Trace File: trace_antd.json (0.6GB, 3.31M events)
Test Project: examples/with-antd


Executive Summary

Key Findings

Metric Value Assessment
Total Wall Time 8,419.8 ms Baseline
Total Thread Work (de-duped) 27,554.5 ms Non-overlapping busy time
Effective Parallelism 3.3x thread_work / wall_time
Working Threads 5 Threads with actual spans
Thread Utilization 65.5% 🆗 Average
Total Spans 1,657,115 All B/E + X events
Meaningful Spans (>= 10us) 567,243 (34.2% of total)
Tracing Noise (< 10us) 1,089,872 (65.8% of total)

Workload Distribution by Tier

Category Tasks Total Time (ms) % of Thread Work
P0: Runtime/Resolution 0 0.0 0.0%
P1: I/O & Heavy Tasks 39,624 3,748.5 13.6%
P3: Asset Pipeline 36,416 3,417.0 12.4%
P4: Bridge/Interop 0 0.0 0.0%
Other 491,203 22,731.8 82.5%

🤖 AI Intelligent Attributions

New section mapping granular tasks to bottlenecks.

Top 10 Batching Candidates

These highly-called tasks are dominated by a single parent. If the parent can batch them into one call, it drastically reduces scheduler overhead.

Task Name Count Top Caller (Attribution) Avg P95 Total Time
analyze ecmascript module 36,736 process module (76%) 100.1 us 0.28 ms 3,677.7 ms

Top 20 Tasks by Total Duration

Total (ms) Count Avg (us) P95 (ms) Max (ms) % Work Task Name Top Caller
8,256.0 209,444 39.4 0.1 10.1 30.0% module write all entrypoints to disk (1%)
4,157.5 70,335 59.1 0.1 210.8 15.1% process module module (15%)
3,677.7 36,736 100.1 0.3 210.7 13.3% analyze ecmascript module process module (76%)
2,785.3 24,954 111.6 0.3 60.9 10.1% code generation chunking (6%)
1,838.8 67,364 27.3 0.0 8.4 6.7% resolving module (30%)
1,695.1 60,874 27.8 0.0 12.9 6.2% internal resolving resolving (30%)
1,372.0 14,865 92.3 0.2 47.5 5.0% chunking write all entrypoints to disk (0%)
1,371.3 32,470 42.2 0.1 8.7 5.0% precompute code generation code generation (31%)
1,157.0 8,451 136.9 0.1 224.7 4.2% write all entrypoints to disk None (0%)
1,137.6 13,790 82.5 0.3 140.4 4.1% compute async module info chunking (0%)
1,047.0 8,055 130.0 0.5 43.9 3.8% parse ecmascript analyze ecmascript module (26%)
635.2 11,348 56.0 0.1 44.1 2.3% compute async chunks compute async chunks (0%)
285.8 1,936 147.6 0.4 16.2 1.0% generate source map code generation (96%)
98.5 868 113.5 0.0 19.6 0.4% compute binding usage info write all entrypoints to disk (0%)
61.4 2,165 28.4 0.0 1.0 0.2% read file parse ecmascript (91%)
60.2 206 292.3 0.5 20.0 0.2% make production chunks chunking (2%)
49.1 1,870 26.3 0.0 8.1 0.2% collect mergeable modules compute merged modules (0%)
38.5 628 61.4 0.1 3.2 0.1% async reference write all entrypoints to disk (1%)
38.0 14 2714.7 9.2 9.7 0.1% apply effects write all entrypoints to disk (7%)
32.6 13 2505.1 9.2 9.7 0.1% write file apply effects (100%)

Duration Distribution

Range Count Percentage
< 10us (noise) 1,089,872 65.8%
10us - 100us 540,859 32.6%
100us - 1ms 21,989 1.3%
1ms - 10ms 4,298 0.3%
10ms - 100ms 91 0.0%
> 100ms 6 0.0%

Action Items

  1. [P0] Use Batching Candidates to pinpoint specific files needing try_join or reduced #[turbo_tasks::function] limits.
  2. [P1] Inspect P95 (ms) for heavy monolith tasks. Focus on long-tail outliers rather than averages.

Report generated by Intelligent Utoopack Performance Analysis Agent

@xusd320 xusd320 disabled auto-merge March 12, 2026 09:42
@xusd320 xusd320 merged commit 602ea4d into next Mar 12, 2026
21 checks passed
@xusd320 xusd320 deleted the fix-unused-exports branch March 12, 2026 09:42
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.

2 participants