Skip to content

⚡ Parallelize file copy and delete operations in HarmonyOS DownloadTask#534

Closed
sunnylqm wants to merge 1 commit intomasterfrom
perf-parallel-file-ops-harmony-9441733629852452380
Closed

⚡ Parallelize file copy and delete operations in HarmonyOS DownloadTask#534
sunnylqm wants to merge 1 commit intomasterfrom
perf-parallel-file-ops-harmony-9441733629852452380

Conversation

@sunnylqm
Copy link
Copy Markdown
Contributor

@sunnylqm sunnylqm commented Mar 29, 2026

  • Refactored sequential await loops for copyFile and unlink in harmony/pushy/src/main/ets/DownloadTask.ts.
  • Implemented concurrent execution using Promise.all().
  • Maintained individual error handling for each operation to preserve existing behavior.
  • Added type assertions to ensure compatibility with ArkTS/TypeScript object iteration.

PR created automatically by Jules for task 9441733629852452380 started by @sunnylqm

Summary by CodeRabbit

  • Performance Improvements
    • Optimized patch update processing by executing file operations concurrently rather than sequentially. File copy and deletion operations during patch application now run in parallel, significantly reducing the time required to complete updates and enhancing the overall user experience during downloads and system maintenance.

…dTask

File deletions and copies in `doPatchFromPpk` were previously executed sequentially using `await` in loops. This commit refactors these operations to use `Promise.all()`, allowing them to execute concurrently and improving overall patch application performance.

Co-authored-by: sunnylqm <615282+sunnylqm@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 29, 2026

📝 Walkthrough

Walkthrough

In doPatchFromPpk, file copying and deletion operations following __diff.json processing were changed from sequential await loops to concurrent execution via Promise.all, while retaining per-operation error handling and maintaining overall control flow.

Changes

Cohort / File(s) Summary
File I/O Parallelization
harmony/pushy/src/main/ets/DownloadTask.ts
Changed post-__diff.json file operations from sequential awaits to concurrent Promise.all for copying and unlinking files; per-operation .catch logging preserved.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

🐰 Hops of joy, files now fly,
Sequential chains released to sky,
Parallel paths make tasks run fleet,
Faster patches, all complete! 🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and clearly describes the main change: parallelizing file copy and delete operations in HarmonyOS DownloadTask, which is the primary refactoring in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf-parallel-file-ops-harmony-9441733629852452380

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
harmony/pushy/src/main/ets/DownloadTask.ts (1)

353-373: Parallelization looks correct; however, silent failures may leave patches in an inconsistent state.

The parallel implementation is sound—copies have unique destinations (object keys), deletes target unique files, and the order (copies → deletes) is preserved via separate Promise.all() calls.

However, swallowing errors via .catch() means a failed copy or delete won't stop the operation—the function proceeds and eventually succeeds. If a critical file fails to copy, the patch could be incomplete or broken at runtime. Consider either:

  1. Collecting failed operations and throwing after all complete (fail-fast with aggregated errors):
Example: Aggregate errors
-        await Promise.all(
-          Object.entries(copies as Record<string, string>).map(([to, from]) =>
-            fileIo
-              .copyFile(
-                `${params.originDirectory}/${from}`,
-                `${params.unzipDirectory}/${to}`,
-              )
-              .catch(error => {
-                console.error('copy error:', error);
-              }),
-          ),
-        );
+        const copyErrors: Array<{ file: string; error: unknown }> = [];
+        await Promise.all(
+          Object.entries(copies as Record<string, string>).map(([to, from]) =>
+            fileIo
+              .copyFile(
+                `${params.originDirectory}/${from}`,
+                `${params.unzipDirectory}/${to}`,
+              )
+              .catch(error => {
+                console.error('copy error:', error);
+                copyErrors.push({ file: to, error });
+              }),
+          ),
+        );
+        if (copyErrors.length > 0) {
+          throw new Error(`Failed to copy ${copyErrors.length} file(s)`);
+        }
  1. Using Promise.allSettled() to continue on failure but still report issues.

If the current swallow-and-continue behavior is intentional (best-effort patching), a brief comment explaining the rationale would help future maintainers.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@harmony/pushy/src/main/ets/DownloadTask.ts` around lines 353 - 373, The
current parallel copy/delete logic swallows errors via .catch() on each Promise,
risking silent incomplete patches; update the block around fileIo.copyFile and
fileIo.unlink (operating on copies, deletes with params.originDirectory and
params.unzipDirectory) to collect failures and surface them after all operations
complete: either use Promise.allSettled() and aggregate any rejected results
into a single thrown Error (or structured error report) or remove the per-item
.catch() and let Promise.all reject to fail-fast; if best-effort behavior is
intentional, add a concise comment explaining that choice and ensure errors are
still logged and reported to callers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@harmony/pushy/src/main/ets/DownloadTask.ts`:
- Around line 353-373: The current parallel copy/delete logic swallows errors
via .catch() on each Promise, risking silent incomplete patches; update the
block around fileIo.copyFile and fileIo.unlink (operating on copies, deletes
with params.originDirectory and params.unzipDirectory) to collect failures and
surface them after all operations complete: either use Promise.allSettled() and
aggregate any rejected results into a single thrown Error (or structured error
report) or remove the per-item .catch() and let Promise.all reject to fail-fast;
if best-effort behavior is intentional, add a concise comment explaining that
choice and ensure errors are still logged and reported to callers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ffbc5434-2e77-4e78-be32-23ec8e04597c

📥 Commits

Reviewing files that changed from the base of the PR and between 099817c and 76ef8e3.

📒 Files selected for processing (1)
  • harmony/pushy/src/main/ets/DownloadTask.ts

@sunnylqm sunnylqm closed this Mar 29, 2026
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.

1 participant