Skip to content

Conversation

@LiHua000
Copy link
Contributor

@LiHua000 LiHua000 commented Aug 5, 2025

  • Replace proportion-based logic with size-based thresholds
  • Fix uniform large files incorrectly using 7z instead of libarchive
  • Add size thresholds: max file > 50MB, total > 200MB, or (total > 100MB && max > 10MB)
  • Maintain backward compatibility with original proportion logic

log: 性能优化

Bug:

Summary by Sourcery

Replace proportion-based logic for selecting libarchive vs 7z on ARM with explicit file size thresholds to fix incorrect plugin selection and optimize performance

Bug Fixes:

  • Correct cases where uniformly large files on ARM were wrongly compressed with 7z instead of libarchive

Enhancements:

  • Add absolute size thresholds for using libarchive: max file >50MB, total >200MB, or (total >100MB and max >10MB), while retaining the original proportion check for fallback

@sourcery-ai
Copy link

sourcery-ai bot commented Aug 5, 2025

Reviewer's Guide

This PR refactors the ARM (aarch64) plugin selection logic by replacing a simple max-file-size proportion check with explicit size-based thresholds to ensure large files use libarchive, while keeping the original proportion-based check as a fallback for backward compatibility.

File-Level Changes

Change Details Files
Refactored ARM plugin selection to use explicit size-based thresholds
  • Introduced max file >50MB threshold
  • Added total size >200MB threshold
  • Added combined threshold: total >100MB and max >10MB
src/source/mainwindow.cpp
Preserved original proportion-based fallback logic
  • Retained >60% max-file-size proportion check as fallback
  • Maintained backward compatibility with original behavior
src/source/mainwindow.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @LiHua000 - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments

### Comment 1
<location> `src/source/mainwindow.cpp:1048` </location>
<code_context>
+        bUseLibarchive = true;
+    }
+    // 大文件占比超过60%使用libarchive
+    else {
+        double maxFileSizeProportion = static_cast<double>(maxFileSize_) / static_cast<double>(m_stCompressParameter.qSize);
+        bUseLibarchive = maxFileSizeProportion > 0.6;
+    }
</code_context>

<issue_to_address>
Potential division by zero if qSize is zero.

Add a check to prevent division when qSize is zero to avoid undefined behavior.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

#ifdef __aarch64__ // 华为arm平台 zip压缩 性能提升. 在多线程场景下使用7z,单线程场景下使用libarchive
double maxFileSizeProportion = static_cast<double>(maxFileSize_) / static_cast<double>(m_stCompressParameter.qSize);
bUseLibarchive = maxFileSizeProportion > 0.6;
// 最大文件超过50MB使用libarchive
Copy link

Choose a reason for hiding this comment

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

issue (bug_risk): Potential division by zero if qSize is zero.

Add a check to prevent division when qSize is zero to avoid undefined behavior.

- Replace proportion-based logic with size-based thresholds
- Fix uniform large files incorrectly using 7z instead of libarchive
- Add size thresholds: max file > 50MB, total > 200MB, or (total > 100MB && max > 10MB)
- Maintain backward compatibility with original proportion logic

log: 性能优化

Bug: https://pms.uniontech.com/bug-view-328359.html
@deepin-ci-robot
Copy link

deepin pr auto review

代码审查意见:

  1. 代码可读性

    • 在条件判断中,注释应该更加详细,解释为什么在特定条件下选择使用 libarchive。例如,注释可以说明为什么最大文件超过50MB、总大小超过200MB、总大小超过100MB且最大文件超过10MB,以及大文件占比超过60%时选择使用 libarchive
  2. 逻辑清晰性

    • 条件判断的顺序可以优化,以减少不必要的计算。例如,如果最大文件超过50MB,那么它肯定也超过了100MB和200MB,因此可以直接返回 true,而不需要继续进行后续的判断。
  3. 性能优化

    • 在条件判断中,maxFileSizeProportion 的计算被重复了三次。可以将这个计算提取出来,避免重复计算。
  4. 代码风格

    • 条件判断中的注释应该使用中文,以保持代码的一致性和可读性。
  5. 代码安全

    • 没有发现明显的安全问题。
  6. 代码维护性

    • 如果将来需要添加更多的条件判断,建议将条件判断封装成一个函数,以提高代码的可维护性。

修改后的代码示例:

void MainWindow::slotCompress(const QVariant &val)
{
    bool bUseLibarchive = false;
    #ifdef __aarch64__
        // 最大文件超过50MB使用libarchive
        if (maxFileSize_ > 50 * 1024 * 1024) {
            bUseLibarchive = true;
        }
        // 总大小超过200MB使用libarchive
        else if (m_stCompressParameter.qSize > 200 * 1024 * 1024) {
            bUseLibarchive = true;
        }
        // 总大小超过100MB且最大文件超过10MB使用libarchive(处理均匀分布的大文件)
        else if (m_stCompressParameter.qSize > 100 * 1024 * 1024 && maxFileSize_ > 10 * 1024 * 1024) {
            bUseLibarchive = true;
        }
        // 大文件占比超过60%使用libarchive
        else {
            double maxFileSizeProportion = static_cast<double>(maxFileSize_) / static_cast<double>(m_stCompressParameter.qSize);
            bUseLibarchive = maxFileSizeProportion > 0.6;
        }
    #else
        bUseLibarchive = false;
    #endif
}

以上修改建议旨在提高代码的可读性、性能和可维护性。

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@LiHua000
Copy link
Contributor Author

/merge

@deepin-bot deepin-bot bot merged commit 290fed2 into linuxdeepin:release/eagle Aug 11, 2025
14 checks passed
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.

3 participants