Skip to content

fix: [zip] improve ARM platform plugin selection for large files#325

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/snipefrom
GongHeng2017:202511211041-snipe-fix
Nov 21, 2025
Merged

fix: [zip] improve ARM platform plugin selection for large files#325
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/snipefrom
GongHeng2017:202511211041-snipe-fix

Conversation

@GongHeng2017
Copy link
Copy Markdown
Contributor

@GongHeng2017 GongHeng2017 commented Nov 21, 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: https://pms.uniontech.com/bug-view-328359.html

Summary by Sourcery

Revise ARM platform zip compression logic to select libarchive based on explicit size thresholds instead of file proportion, improving performance and correctness

Bug Fixes:

  • Fix uniform large files incorrectly using 7z instead of libarchive on ARM

Enhancements:

  • Replace proportion-based plugin selection with size-based thresholds (max file >50MB, total >200MB, or total >100MB and max >10MB) for choosing libarchive on ARM
  • Retain fallback to original proportion-based logic for backward compatibility

- 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
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Nov 21, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Refactors the ARM platform ZIP plugin selection by replacing the old proportion-only logic with explicit size-based thresholds for choosing libarchive over 7z while preserving backward compatibility.

Class diagram for updated compression parameter usage

classDiagram
    class MainWindow {
        +void slotCompress(QVariant val)
        -bool bUseLibarchive
        -size_t maxFileSize_
        -CompressParameter m_stCompressParameter
    }
    class CompressParameter {
        +size_t qSize
    }
    MainWindow --> CompressParameter : uses
Loading

Flow diagram for updated ARM ZIP plugin selection logic

flowchart TD
    A["Start compression (ARM platform)"] --> B["Check if max file size > 50MB"]
    B -- Yes --> F["Use libarchive"]
    B -- No --> C["Check if total size > 200MB"]
    C -- Yes --> F
    C -- No --> D["Check if total size > 100MB AND max file size > 10MB"]
    D -- Yes --> F
    D -- No --> E["Check if max file size proportion > 60%"]
    E -- Yes --> F
    E -- No --> G["Use 7z"]
Loading

File-Level Changes

Change Details Files
Overhauled ARM compression backend selection to use explicit size thresholds
  • Use libarchive when a single file exceeds 50 MB
  • Use libarchive when total archive size exceeds 200 MB
  • Use libarchive when total >100 MB and max file >10 MB (handles uniform large files)
  • Retain fallback to original >60% size proportion check
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

@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

我来对这段代码进行审查分析:

  1. 代码逻辑分析:
    这段代码主要是在华为ARM平台上根据文件大小特征来选择使用libarchive还是7z进行压缩。新的逻辑相比原来的比例判断更加细致,增加了多个具体大小的阈值判断。

  2. 改进建议:

(1) 代码可维护性:

  • 建议将魔数(50MB、200MB等)定义为常量,便于统一管理和修改
  • 可以考虑将判断逻辑封装成一个单独的函数,提高代码的可读性和复用性

(2) 代码性能:

  • 目前的多个if-else判断是合理的,因为这些都是互斥的条件
  • 除法运算只在最后需要时才执行,这是很好的优化

(3) 代码安全:

  • 整数相乘时要注意溢出风险,建议使用size_t类型
  • 除法运算前应该检查分母是否为0
  1. 重构建议代码:
// 定义常量
constexpr size_t LARGE_FILE_THRESHOLD = 50 * 1024 * 1024;  // 50MB
constexpr size_t TOTAL_SIZE_LARGE_THRESHOLD = 200 * 1024 * 1024;  // 200MB
constexpr size_t TOTAL_SIZE_MEDIUM_THRESHOLD = 100 * 1024 * 1024;  // 100MB
constexpr size_t MEDIUM_FILE_THRESHOLD = 10 * 1024 * 1024;  // 10MB
constexpr double LARGE_FILE_PROPORTION_THRESHOLD = 0.6;

// 判断是否使用libarchive的函数
bool shouldUseLibarchive(size_t maxFileSize, size_t totalSize) {
    // 防止除零错误
    if (totalSize == 0) return false;
    
    if (maxFileSize > LARGE_FILE_THRESHOLD) {
        return true;
    }
    if (totalSize > TOTAL_SIZE_LARGE_THRESHOLD) {
        return true;
    }
    if (totalSize > TOTAL_SIZE_MEDIUM_THRESHOLD && 
        maxFileSize > MEDIUM_FILE_THRESHOLD) {
        return true;
    }
    
    double proportion = static_cast<double>(maxFileSize) / static_cast<double>(totalSize);
    return proportion > LARGE_FILE_PROPORTION_THRESHOLD;
}

void MainWindow::slotCompress(const QVariant &val)
{
    bool bUseLibarchive = false;
#ifdef __aarch64__
    bUseLibarchive = shouldUseLibarchive(maxFileSize_, m_stCompressParameter.qSize);
#else
    bUseLibarchive = false;
#endif
    // ... 其余代码
}
  1. 主要改进点:
  • 使用常量替代魔数
  • 封装判断逻辑到独立函数
  • 增加除零保护
  • 使用size_t类型处理文件大小
  • 提高代码可读性和可维护性
  1. 性能考虑:
  • 重构后的代码性能基本与原代码相同
  • 判断顺序按照从最可能的情况到最不可能的情况排列
  • 除法运算仅在必要时执行

这样的改进使代码更加健壮、可维护,同时保持了原有的性能特征。

Copy link
Copy Markdown

@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 there - I've reviewed your changes - here's some feedback:

  • Consider extracting the numeric thresholds (50MB, 200MB, 100MB, 10MB) into named constants or configuration parameters for better readability and easier future tuning.
  • Add a guard to ensure m_stCompressParameter.qSize is nonzero before calculating maxFileSizeProportion to avoid a potential division-by-zero in the fallback branch.
  • The original comment mentions single- vs multi-thread scenarios, but the new logic is purely size-based—update or remove the threading reference to keep the code comments aligned with the implementation.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the numeric thresholds (50MB, 200MB, 100MB, 10MB) into named constants or configuration parameters for better readability and easier future tuning.
- Add a guard to ensure m_stCompressParameter.qSize is nonzero before calculating maxFileSizeProportion to avoid a potential division-by-zero in the fallback branch.
- The original comment mentions single- vs multi-thread scenarios, but the new logic is purely size-based—update or remove the threading reference to keep the code comments aligned with the implementation.

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.

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: GongHeng2017, lzwind

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

@GongHeng2017
Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot deepin-bot bot merged commit b107a2d into linuxdeepin:develop/snipe Nov 21, 2025
15 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