-
Notifications
You must be signed in to change notification settings - Fork 74
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(tree-shaking): optimize import namespace used all exports to partial used of source modules #1584
Conversation
…in dep module replace USE ALL export to partial used exports
Walkthrough此次更改引入了一个新的函数 Changes
Possibly related PRs
Poem
Tip OpenAI O1 model for chat
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Additional comments not posted (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1584 +/- ##
==========================================
+ Coverage 62.03% 62.24% +0.20%
==========================================
Files 127 128 +1
Lines 15353 15512 +159
==========================================
+ Hits 9524 9655 +131
- Misses 5829 5857 +28 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Outside diff range and nitpick comments (1)
e2e/fixtures/tree-shaking.import_star/src/index.tsx (1)
1-8
: 代码段看起来不错,正确演示了命名空间导入和访问特定导出的用法。这段代码通过使用命名空间导入
math
和math2
模块,并访问它们的特定导出,如needKeep
和shouldKeep
,来验证树摇优化的行为。建议添加注释来说明这段代码的目的,即作为树摇优化的测试用例。这将有助于其他开发人员理解代码的意图。
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- crates/mako/src/plugins/tree_shaking/remove_useless_stmts.rs (3 hunks)
- e2e/fixtures/tree-shaking.import_star/expect.js (1 hunks)
- e2e/fixtures/tree-shaking.import_star/src/index.tsx (1 hunks)
- e2e/fixtures/tree-shaking.import_star/src/mod2.ts (1 hunks)
- packages/mako/binding.d.ts (0 hunks)
Files not reviewed due to no reviewable changes (1)
- packages/mako/binding.d.ts
Files skipped from review as they are similar to previous changes (1)
- e2e/fixtures/tree-shaking.import_star/expect.js
Additional comments not posted (3)
e2e/fixtures/tree-shaking.import_star/src/mod2.ts (2)
1-3
: 没有问题!该函数的逻辑正确,实现准确无误。
5-7
: 看起来不错!函数的实现是正确的,没有发现任何问题。
crates/mako/src/plugins/tree_shaking/remove_useless_stmts.rs (1)
240-300
: 代码看起来不错!这个优化可以提高模块导入处理的效率。新增的
optimize_import_namespace
函数通过分析显式属性访问来识别和优化命名空间导入。它有效地将命名空间导入替换为仅包含已访问属性的命名导入,从而减少了不必要的导入。该函数的逻辑流程结构清晰,易于理解,并且很好地集成到现有的remove_useless_stmts
函数中。
+1 |
problem
after building, both
square
andcube
are kept in dist js, butcube
is not necessary.in this case, we can figure out that only square is used, so we can optimize that math.js 's used exports from
ALL_USED
toPartial(['square'])
how to
if all accesses to the namespace are "explicit", we can say the namespace used and only used these exports of the source module.
"explicit" is define as these two types
namespace.foo
namespace['foo']
if there is an no-explicit access in code, we will stop thes optimize; eg.
determining if all accesses to the namespace are "explicit" is easy.
in intuition, the count of namespace appears in explicit member expr should equal with the count of namespace ident appears; but don't forget the
import * as namespace
so
if count(namespace ident appears) - count(namespace_member_access ) == 1
we can optimize the namespace usage .Summary by CodeRabbit
新功能
optimize_import_namespace
功能,优化命名空间导入处理。needKeep
和needNotKeep
函数,提供基本数学运算功能。修复
TransformOutput
接口,简化了输出转换的处理方式。