fix: [zip] improve ARM platform plugin selection for large files#325
Conversation
- 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
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors 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 usageclassDiagram
class MainWindow {
+void slotCompress(QVariant val)
-bool bUseLibarchive
-size_t maxFileSize_
-CompressParameter m_stCompressParameter
}
class CompressParameter {
+size_t qSize
}
MainWindow --> CompressParameter : uses
Flow diagram for updated ARM ZIP plugin selection logicflowchart 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"]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto review我来对这段代码进行审查分析:
(1) 代码可维护性:
(2) 代码性能:
(3) 代码安全:
// 定义常量
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
// ... 其余代码
}
这样的改进使代码更加健壮、可维护,同时保持了原有的性能特征。 |
There was a problem hiding this comment.
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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/merge |
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:
Enhancements: