Skip to content

feat: limit plugin installation load#1951

Merged
RohitKushvaha01 merged 2 commits intoAcode-Foundation:mainfrom
RohitKushvaha01:main
Mar 17, 2026
Merged

feat: limit plugin installation load#1951
RohitKushvaha01 merged 2 commits intoAcode-Foundation:mainfrom
RohitKushvaha01:main

Conversation

@RohitKushvaha01
Copy link
Copy Markdown
Member

@RohitKushvaha01 RohitKushvaha01 marked this pull request as draft March 16, 2026 12:06
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 16, 2026

Greptile Summary

This PR addresses excessive concurrent I/O during plugin installation by replacing the original "fire all files in parallel" approach (Promise.allSettled(promises)) with a sequential batch loop that processes two ZIP entries at a time, yielding to the event loop between batches via setTimeout(0).

Key changes:

  • ZIP file entries are now extracted in batches of limit = 2 rather than all at once, reducing peak memory and I/O load on mobile devices.
  • A await new Promise((r) => setTimeout(r, 0)) yield is inserted between batches to keep the UI thread responsive during installation.
  • processFile is extracted as a named async inner function for clarity.
  • Minor readability improvements: cached zip.files[file] into entry, replaced !!zip.files[file].dir with entry.dir, and used !== -1 instead of >= 0 for the slash index guard.
  • await new Promise((r) => setTimeout(r, 0)) fires on every loop iteration including the last one, adding a small unnecessary delay after all files have finished processing (see inline comment).

Confidence Score: 4/5

  • Safe to merge — the batching logic is correct and the regression risk is low.
  • The change is well-scoped, logically sound, and addresses a genuine mobile-performance concern. The only issue found is a trivial last-batch yield that adds one unnecessary event-loop tick — no correctness or security impact. The error-handling contract and overall installation flow are unchanged.
  • No files require special attention.

Important Files Changed

Filename Overview
src/lib/installPlugin.js Introduces batched ZIP-entry extraction (batch size 2) with a setTimeout(0) yield between batches to reduce concurrent I/O load during plugin installation. Minor cleanup included (removed !! double-negation, use of cached entry reference, !== -1 guard). One minor issue: setTimeout(0) fires on every iteration including the last batch, adding an unnecessary event-loop yield after all files are processed.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[installPlugin called] --> B[Download plugin ZIP]
    B --> C[Parse plugin.json & resolve deps]
    C --> D[files = Object.keys zip.files\nlimit = 2]
    D --> E{i < files.length?}
    E -- Yes --> F[batch = files.slice i, i+limit]
    F --> G[Promise.allSettled batch.map processFile]
    G --> H[await setTimeout 0\nYield to UI thread]
    H --> I[i += limit]
    I --> E
    E -- No --> J{ignoredUnsafeEntries.size > 0?}
    J -- Yes --> K[Show warning in loaderDialog]
    J -- No --> L[loadPlugin / depsLoaders]
    K --> L
    L --> M[state.save\ndeleteRedundantFiles]

    subgraph processFile [processFile per entry]
        P1[Normalize path] --> P2{isUnsafeAbsolutePath?}
        P2 -- Yes --> P3[Add to ignoredUnsafeEntries, return]
        P2 -- No --> P4[sanitizeZipPath]
        P4 --> P5{isDirEntry?}
        P5 -- Yes --> P6[createFileRecursive dir]
        P5 -- No --> P7[Ensure parent dir exists]
        P7 --> P8[Read ArrayBuffer from entry]
        P8 --> P9{state.isUpdated?}
        P9 -- No --> P10[Skip write, return]
        P9 -- Yes --> P11[writeFile to pluginDir]
    end
Loading

Last reviewed commit: 1c4bf36

@RohitKushvaha01 RohitKushvaha01 marked this pull request as ready for review March 17, 2026 02:28
@RohitKushvaha01 RohitKushvaha01 merged commit b70c19d into Acode-Foundation:main Mar 17, 2026
8 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.

2 participants