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

perf: group chunks with right-first dfs #1554

Merged
merged 8 commits into from
Sep 3, 2024

Conversation

xusd320
Copy link
Contributor

@xusd320 xusd320 commented Aug 31, 2024

The previous impl of chunk dependencies by BFS is not correct, and in that way, must use Iter::position (compute as O(n)) api to insert depencies before parent. Just change the way by post order DFS, and remove calls of Iter::position.

Why before impl it not correct? With below files:

a.css

@import "b.css";
@import "c.css";

.demo {
 color: red
}

b.css

@import "c.css";

.test {
 color: blue
}

c.css

@import "c.css";

.demo {
 color: yellow
}

index.css

@import "a.css";
@import "b.css";

By BFS impl, the ordered modules will be

c.ss
b.css
c.ss
a.css
b.css
index.css

And after deduplicating, the modules order will be

c.ss
a.css
b.css
index.css

the result css chunk is

.demo {
 color: yellow
}
.demo {
 color: red
}
.test {
 color: blue
}

Because in index.css, b.css is been imported after a.css, and b.css also import c.css, so c.css will overlap upon a.css again. So that this result is not correct.

By post order DFS, the ordered modules will be

c.ss
b.css
c.ss
a.css
c.css
b.css
index.css

That result is correct.
Coincidely, in parcel-bundler, these is a same case, https://github.com/parcel-bundler/lightningcss/blob/ad2ec9f10309ac27261a996210023b8e8ad3c793/src/bundler.rs#L1632, also see the same discussion parcel-bundler/parcel#5840.

When building big project, this impl is 8x faster than before.
Before:
image

After:
image

Summary by CodeRabbit

Summary by CodeRabbit

  • 新功能
    • 改进了模块依赖处理逻辑,增强了模块访问的灵活性和效率。
    • 优化了图结构中的边添加逻辑,提高了代码可读性和准确性。
    • 引入了多个测试脚本,以验证CSS合并功能在不同场景下的正确性。
  • 修复
    • 解决了与 petgraph 库相关的邻接模块顺序问题。

Copy link
Contributor

coderabbitai bot commented Aug 31, 2024

Walkthrough

此次更改涉及多个文件的结构和逻辑调整,主要集中在依赖处理和代码优化方面。关键改动包括对sync_dependencies_chunk方法的邻接块处理进行优化,以及在optimize_chunk.rs中使用更现代的Rust风格替代传统循环,提升代码的可读性和清晰度。此外,新增了多个测试脚本以验证CSS合并功能的正确性。

Changes

文件 更改摘要
crates/mako/src/generate/chunk_graph.rs 修改sync_dependencies_chunk方法,增加邻接块处理的中间变量,明确邻接块顺序反转。
crates/mako/src/generate/optimize_chunk.rs 改进边添加逻辑,使用flat_mapfor_each替代传统循环,提升代码的可读性。
crates/mako/src/generate/group_chunk.rs 重构visit_modules函数,支持泛型类型,简化模块依赖处理逻辑。
e2e/fixtures/css.css-merge-deep-level/expect.js 新增测试脚本,验证CSS样式合并的功能,检查特定类定义的存在。
e2e/fixtures/css.css-merge-in-css-multi-imports/expect.js 新增测试脚本,验证多重导入上下文中的CSS合并功能。
e2e/fixtures/css.css-merge-reverse-by-descent/expect.js 新增测试脚本,验证CSS合并功能,确保特定类定义的存在。

Sequence Diagram(s)

sequenceDiagram
    participant A as 用户
    participant B as 模块处理器
    participant C as 依赖图
    A->>B: 调用 sync_dependencies_chunk
    B->>C: 处理邻接块
    C-->>B: 返回邻接块列表
    B-->>A: 返回处理结果
Loading

兔子在草地上蹦跳,
模块重构如春风拂,
依赖清晰不再乱,
代码简洁乐无边。
兔子欢呼声不断,
编程世界真美妙!
🐇✨


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?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Tip

Early access features: enabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8b79017 and 5e85234.

Files selected for processing (25)
  • crates/mako/src/generate/group_chunk.rs (4 hunks)
  • e2e/fixtures/code-splitting.complex/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-deep-level/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-deep-level/mako.config.json (1 hunks)
  • e2e/fixtures/css.css-merge-deep-level/src/a.css (1 hunks)
  • e2e/fixtures/css.css-merge-deep-level/src/a1.css (1 hunks)
  • e2e/fixtures/css.css-merge-deep-level/src/b.css (1 hunks)
  • e2e/fixtures/css.css-merge-deep-level/src/b1.css (1 hunks)
  • e2e/fixtures/css.css-merge-deep-level/src/c.css (1 hunks)
  • e2e/fixtures/css.css-merge-deep-level/src/c1.css (1 hunks)
  • e2e/fixtures/css.css-merge-deep-level/src/index.ts (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/mako.config.json (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/a.css (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/b.css (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/c.css (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/index.css (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/index.ts (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/mako.config.json (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/a.css (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/b.css (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/c.css (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/d.css (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/index.ts (1 hunks)
Files skipped from review due to trivial changes (20)
  • e2e/fixtures/css.css-merge-deep-level/mako.config.json
  • e2e/fixtures/css.css-merge-deep-level/src/a.css
  • e2e/fixtures/css.css-merge-deep-level/src/a1.css
  • e2e/fixtures/css.css-merge-deep-level/src/b.css
  • e2e/fixtures/css.css-merge-deep-level/src/b1.css
  • e2e/fixtures/css.css-merge-deep-level/src/c.css
  • e2e/fixtures/css.css-merge-deep-level/src/c1.css
  • e2e/fixtures/css.css-merge-deep-level/src/index.ts
  • e2e/fixtures/css.css-merge-in-css-multi-imports/mako.config.json
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/a.css
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/b.css
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/c.css
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/index.css
  • e2e/fixtures/css.css-merge-in-css-multi-imports/src/index.ts
  • e2e/fixtures/css.css-merge-reverse-by-descent/mako.config.json
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/a.css
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/b.css
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/c.css
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/d.css
  • e2e/fixtures/css.css-merge-reverse-by-descent/src/index.ts
Additional comments not posted (5)
e2e/fixtures/css.css-merge-in-css-multi-imports/expect.js (1)

1-21: 测试逻辑和实现审核通过。

此测试使用 Node.js 断言来验证 index.css 文件中是否包含特定的 CSS 规则,并且顺序正确。这对于验证新的 DFS 方法是否正确处理 CSS 模块的依赖关系和顺序至关重要。

e2e/fixtures/css.css-merge-reverse-by-descent/expect.js (1)

1-23: 测试逻辑和实现审核通过。

此测试使用 Node.js 断言来验证 index.css 文件中是否包含特定的 CSS 规则,并且顺序正确。这对于验证新的 DFS 方法是否正确处理 CSS 模块的依赖关系和顺序至关重要。

e2e/fixtures/css.css-merge-deep-level/expect.js (1)

1-30: 测试逻辑和实现审核通过。

此测试使用 Node.js 断言来验证 index.css 文件中是否包含特定的 CSS 规则,并且顺序正确。这对于验证新的 DFS 方法是否正确处理 CSS 模块的依赖关系和顺序至关重要。

e2e/fixtures/code-splitting.complex/expect.js (1)

48-48: 验证正则表达式中的字符串数组更改。

此更改可能反映了块命名或组织方式的更新。请确保此更改与整个文件的上下文以及测试的准确性相符。

crates/mako/src/generate/group_chunk.rs (1)

485-506: 审查重构后的 visit_modules 函数。

此函数现在使用泛型并返回 Vec<T>,这应提供更多灵活性并可能通过避免不必要的变更来提高性能。建议添加文档来解释泛型的使用及其对函数行为的影响。

Copy link

codecov bot commented Aug 31, 2024

Codecov Report

Attention: Patch coverage is 62.50000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 61.63%. Comparing base (8b79017) to head (0cae8b2).
Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
crates/mako/src/generate/optimize_chunk.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1554      +/-   ##
==========================================
- Coverage   61.63%   61.63%   -0.01%     
==========================================
  Files         127      127              
  Lines       15294    15294              
==========================================
- Hits         9427     9426       -1     
- Misses       5867     5868       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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, codebase verification and nitpick comments (1)
crates/mako/src/generate/chunk_graph.rs (1)

114-121: 代码更改看起来不错,但有一个小建议。

这些更改很好地解决了petgraph库中邻居排序的问题。通过引入中间变量ret并显式反转顺序,代码变得更加清晰和易于理解。

建议将变量ret重命名为更具描述性的名称,例如neighborsdependency_chunks,以更好地反映其内容。这样可以进一步提高代码的可读性。

例如:

-        let ret = self
+        let neighbors = self
             .graph
             .neighbors_directed(*idx, Direction::Outgoing)
             .filter(|idx| matches!(self.graph[*idx].chunk_type, ChunkType::Sync))
             .map(|idx| self.graph[idx].id.clone())
             .collect::<Vec<ChunkId>>();
         // The neighbors ordering is reversed, see https://github.com/petgraph/petgraph/issues/116
-        ret.into_iter().rev().collect()
+        neighbors.into_iter().rev().collect()
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5e85234 and 083e368.

Files selected for processing (2)
  • crates/mako/src/generate/chunk_graph.rs (1 hunks)
  • e2e/fixtures/code-splitting.complex/expect.js (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • e2e/fixtures/code-splitting.complex/expect.js

@xusd320 xusd320 force-pushed the perf/group-chunks-with-post-order-dfs branch from 083e368 to d97a8f8 Compare September 2, 2024 17:42
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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, codebase verification and nitpick comments (1)
crates/mako/src/generate/optimize_chunk.rs (1)

472-481: 优化了边的添加逻辑,提高了代码可读性和性能

这个改动将原来的for循环替换为更加函数式的方法,使用了flat_mapfor_each。这种方式不仅提高了代码的可读性,还可能带来轻微的性能提升。

值得注意的是,代码中反转了邻居的顺序(tos.iter().rev()),这是为了解决petgraph库中的一个已知问题。

建议修复注释中的拼写错误:

-                // so need to add egde by reversed order
+                // so need to add edge by reversed order
Tools
GitHub Check: Spell Check

[warning] 476-476:
"egde" should be "edge".

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 083e368 and d97a8f8.

Files selected for processing (2)
  • crates/mako/src/generate/optimize_chunk.rs (2 hunks)
  • e2e/fixtures/code-splitting.complex/expect.js (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • e2e/fixtures/code-splitting.complex/expect.js
Additional context used
GitHub Check: Spell Check
crates/mako/src/generate/optimize_chunk.rs

[warning] 476-476:
"egde" should be "edge".

Additional comments not posted (1)
crates/mako/src/generate/optimize_chunk.rs (1)

513-515: 简化了边的添加逻辑

这个改动将原来的for循环替换为for_each方法,使代码更加简洁和易读。这种改变保持了原有的功能,同时采用了更现代的Rust编程风格。

@xusd320 xusd320 force-pushed the perf/group-chunks-with-post-order-dfs branch from d97a8f8 to a2ad316 Compare September 3, 2024 02:04
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d97a8f8 and a2ad316.

Files selected for processing (6)
  • crates/mako/src/generate/chunk_graph.rs (1 hunks)
  • crates/mako/src/generate/optimize_chunk.rs (2 hunks)
  • e2e/fixtures/code-splitting.complex/expect.js (2 hunks)
  • e2e/fixtures/css.css-merge-deep-level/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/expect.js (1 hunks)
Files skipped from review as they are similar to previous changes (6)
  • crates/mako/src/generate/chunk_graph.rs
  • crates/mako/src/generate/optimize_chunk.rs
  • e2e/fixtures/code-splitting.complex/expect.js
  • e2e/fixtures/css.css-merge-deep-level/expect.js
  • e2e/fixtures/css.css-merge-in-css-multi-imports/expect.js
  • e2e/fixtures/css.css-merge-reverse-by-descent/expect.js

@xusd320 xusd320 force-pushed the perf/group-chunks-with-post-order-dfs branch from a2ad316 to 26c5a2f Compare September 3, 2024 02:58
@xusd320 xusd320 force-pushed the perf/group-chunks-with-post-order-dfs branch from 26c5a2f to c99150c Compare September 3, 2024 03:00
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Inline review comments failed to post

Actionable comments posted: 1

Outside diff range, codebase verification and nitpick comments (2)
crates/mako/src/generate/group_chunk.rs (2)

Line range hint 395-425: 依赖收集逻辑的改进

新的实现使用后序深度优先搜索来收集依赖,这是一个很好的改进。然而,在将模块添加到chunk时,当前的实现可能会导致顺序问题。

考虑修改添加模块到chunk的逻辑,以保持正确的顺序:

- while let Some(dep) = chunk_deps.pop() {
-     chunk.add_module(dep);
- }
+ for dep in chunk_deps.into_iter().rev() {
+     chunk.add_module(dep);
+ }

这样可以确保模块按照后序遍历的顺序被添加到chunk中,保持了正确的依赖顺序。


485-509: 有关后序DFS的注释很有帮助

这些注释清晰地解释了使用后序DFS的原因,并提供了一个很好的例子来说明依赖应该如何排序。这对于代码的可维护性来说是一个很大的改进。

为了使注释更加完整,可以考虑添加一行解释为什么c.css在最终顺序中只出现一次:

 * ----------
 * note that c.css, b.css, c.css before a.css will be deduplicated.
+* c.css only appears once in the final order due to deduplication.
 */

这可以帮助读者更好地理解去重过程。

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a2ad316 and 26c5a2f.

Files selected for processing (6)
  • crates/mako/src/generate/chunk_graph.rs (1 hunks)
  • crates/mako/src/generate/group_chunk.rs (4 hunks)
  • crates/mako/src/generate/optimize_chunk.rs (2 hunks)
  • e2e/fixtures/css.css-merge-deep-level/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/expect.js (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • crates/mako/src/generate/chunk_graph.rs
  • crates/mako/src/generate/optimize_chunk.rs
  • e2e/fixtures/css.css-merge-deep-level/expect.js
  • e2e/fixtures/css.css-merge-in-css-multi-imports/expect.js
  • e2e/fixtures/css.css-merge-reverse-by-descent/expect.js
Additional comments not posted (1)
crates/mako/src/generate/group_chunk.rs (1)

1-2: 导入更改看起来不错。

新添加的导入是必要的,并且与后续的代码更改相符。

Comments failed to post (1)
crates/mako/src/generate/group_chunk.rs (1)

510-531: visit_modules 函数的泛化和优化

函数的泛化是一个很好的改进,使其更加灵活和可重用。然而,当前的实现可能在某些情况下不够高效。

考虑使用 Vecretain 方法来优化去重逻辑:

fn visit_modules<F, T>(mut queue: Vec<T>, visited: Option<HashSet<T>>, mut callback: F) -> Vec<T>
where
    F: FnMut(&T) -> Vec<T>,
    T: Hash + Eq + Clone,
{
    let mut post_order_dfs_ret: Vec<T> = Vec::new();
    let mut visited = visited.unwrap_or_default();

    while !queue.is_empty() {
        queue.retain(|id| {
            if !visited.contains(id) {
                visited.insert(id.clone());
                post_order_dfs_ret.push(id.clone());
                queue.extend(callback(id));
                false
            } else {
                true
            }
        });
    }

    post_order_dfs_ret
}

这个优化可以减少内存分配,并可能在某些情况下提高性能。

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 26c5a2f and c99150c.

Files selected for processing (6)
  • crates/mako/src/generate/chunk_graph.rs (1 hunks)
  • crates/mako/src/generate/group_chunk.rs (4 hunks)
  • crates/mako/src/generate/optimize_chunk.rs (2 hunks)
  • e2e/fixtures/css.css-merge-deep-level/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-in-css-multi-imports/expect.js (1 hunks)
  • e2e/fixtures/css.css-merge-reverse-by-descent/expect.js (1 hunks)
Files skipped from review as they are similar to previous changes (5)
  • crates/mako/src/generate/chunk_graph.rs
  • crates/mako/src/generate/group_chunk.rs
  • e2e/fixtures/css.css-merge-deep-level/expect.js
  • e2e/fixtures/css.css-merge-in-css-multi-imports/expect.js
  • e2e/fixtures/css.css-merge-reverse-by-descent/expect.js
Additional context used
GitHub Check: codecov/patch
crates/mako/src/generate/optimize_chunk.rs

[warning] 472-472: crates/mako/src/generate/optimize_chunk.rs#L472
Added line #L472 was not covered by tests


[warning] 475-477: crates/mako/src/generate/optimize_chunk.rs#L475-L477
Added lines #L475 - L477 were not covered by tests


[warning] 509-509: crates/mako/src/generate/optimize_chunk.rs#L509
Added line #L509 was not covered by tests


[warning] 511-511: crates/mako/src/generate/optimize_chunk.rs#L511
Added line #L511 was not covered by tests

Additional comments not posted (2)
crates/mako/src/generate/optimize_chunk.rs (2)

472-477: 代码更改提高了可读性和性能

这个更改使用了更加惯用的 Rust 风格,将传统的 for 循环替换为 flat_mapfor_each 的组合。这种方法可能会提高性能,并且代码更加简洁。

为了提高可读性,建议添加一个简短的注释来解释这个转换:

+// 使用 flat_map 和 for_each 来高效地处理边缘关系
edges_map
    .iter()
    .flat_map(|(from, tos)| tos.iter().map(move |to| (from, to)))
    .for_each(|(from, to)| {
        chunk_graph.add_edge(from, to);
    });

这些新添加的行目前没有被测试覆盖。建议添加相应的单元测试来确保这个逻辑的正确性。以下是一个验证测试覆盖率的脚本:

如果这些测试不存在,我可以协助您编写相应的单元测试。

Tools
GitHub Check: codecov/patch

[warning] 472-472: crates/mako/src/generate/optimize_chunk.rs#L472
Added line #L472 was not covered by tests


[warning] 475-477: crates/mako/src/generate/optimize_chunk.rs#L475-L477
Added lines #L475 - L477 were not covered by tests


509-511: 代码更改提高了一致性

这个更改与 apply_optimize_infos 方法的修改保持一致,使用 for_each 替换了传统的 for 循环。这种方法使代码更加简洁和惯用。

代码变更看起来不错,保持了与之前更改的一致性。

这些新添加的行目前没有被测试覆盖。建议添加相应的单元测试来确保这个逻辑的正确性。以下是一个验证测试覆盖率的脚本:

如果这些测试不存在,我可以协助您编写相应的单元测试。

Tools
GitHub Check: codecov/patch

[warning] 509-509: crates/mako/src/generate/optimize_chunk.rs#L509
Added line #L509 was not covered by tests


[warning] 511-511: crates/mako/src/generate/optimize_chunk.rs#L511
Added line #L511 was not covered by tests

@stormslowly
Copy link
Member

nice shot!

rightmost and deepest brings highest priority is so awesome!

@stormslowly
Copy link
Member

stormslowly commented Sep 3, 2024

after this pr is pub modules: LinkedHashSet<ModuleId>, in Chunk struct still necessary?

@xusd320
Copy link
Contributor Author

xusd320 commented Sep 3, 2024

after this pr is pub modules: LinkedHashSet<ModuleId>, in Chunk struct still necessary?

We need a hash_module check, and need iter by insertion order, at this point, there is no difference between LinkedHashSet and IndexSet.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c99150c and 0cae8b2.

Files selected for processing (1)
  • crates/mako/src/generate/chunk_graph.rs (1 hunks)
Additional comments not posted (1)
crates/mako/src/generate/chunk_graph.rs (1)

114-122: 改进了sync_dependencies_chunk方法的实现

这个变更通过引入ret变量并在返回前反转其顺序,解决了petgraph库中邻居节点顺序的问题。

这个修改提高了代码的清晰度和正确性。建议添加一个简短的注释,解释为什么需要反转顺序,以便future维护者更容易理解。

例如:

// 由于petgraph库的特性,邻居节点的顺序是相反的,所以需要反转
ret.into_iter().rev().collect()

@xusd320 xusd320 merged commit 5a0a0dc into master Sep 3, 2024
17 of 18 checks passed
@xusd320 xusd320 deleted the perf/group-chunks-with-post-order-dfs branch September 3, 2024 09:37
@coderabbitai coderabbitai bot mentioned this pull request Sep 13, 2024
@xusd320 xusd320 changed the title perf: group chunks with post order dfs perf: group chunks with right-first dfs Oct 9, 2024
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