Skip to content

⚡ Bolt: [performance improvement] Parallelize FileReader conversions#415

Closed
aafre wants to merge 1 commit into
mainfrom
bolt-performance-parallelize-file-readers-13902053794740086724
Closed

⚡ Bolt: [performance improvement] Parallelize FileReader conversions#415
aafre wants to merge 1 commit into
mainfrom
bolt-performance-parallelize-file-readers-13902053794740086724

Conversation

@aafre
Copy link
Copy Markdown
Owner

@aafre aafre commented Mar 24, 2026

💡 What: Refactored the sequential await loop in useIconRegistry.ts's exportIconsForYAML function to use Promise.all with a concurrent .map().
🎯 Why: FileReader operations are I/O-bound. Processing them sequentially adds unnecessary delay, especially for users with numerous icons. This acts as a bottleneck when exporting registry data.
📊 Impact: Expected to significantly reduce total conversion time for batches of icons by taking advantage of asynchronous I/O parallelization, resulting in faster export and storage operations.
🔬 Measurement: Verify by executing an export via useIconRegistry with multiple mock icons and measuring execution time or observing faster UI resolution when generating payload data for YAML or storage.


PR created automatically by Jules for task 13902053794740086724 started by @aafre

Co-authored-by: aafre <8656674+aafre@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.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial performance enhancement to the icon export functionality. By transitioning from a sequential processing loop to a parallel execution model using Promise.all for FileReader operations, the system can now handle multiple icon conversions concurrently. This change directly targets and resolves a bottleneck in the export process, leading to a much faster and more responsive user experience when dealing with numerous icons.

Highlights

  • Performance Improvement: Refactored the exportIconsForYAML function in useIconRegistry.ts to parallelize FileReader operations using Promise.all and Array.prototype.map, replacing a sequential await loop.
  • I/O-bound Task Optimization: Addressed the inefficiency of sequential FileReader operations, which are I/O-bound, to significantly reduce export time for multiple icons.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request optimizes the useIconRegistry hook by parallelizing FileReader conversions for icons, transitioning from a sequential for...of loop to concurrent processing using Promise.all and Array.prototype.map. This performance improvement is also documented in a new .Jules/bolt.md file. A review comment highlights that the current parallelized implementation mutates an external exportData object within the map callback, which is an anti-pattern that introduces side effects and could lead to race conditions. A more functional approach is suggested where the map operation returns the necessary data, and the exportData object is then constructed from these returned values.

Comment on lines 170 to +192
const exportData: IconExportData = {};

for (const filename of targetFilenames) {
const entry = registry[filename];
if (entry) {
try {
const base64Data = await fileToBase64(entry.file);
exportData[filename] = {
data: base64Data,
type: entry.file.type,
size: entry.file.size,
uploadedAt: entry.uploadedAt.toISOString(),
};
} catch (error) {
console.warn(`Failed to export icon ${filename}:`, error);
// ⚡ Bolt Performance Optimization:
// Parallelize independent I/O-bound tasks (FileReader conversions) using Promise.all
// instead of sequential await loops. This significantly reduces total conversion time for multiple icons.
await Promise.all(
targetFilenames.map(async (filename) => {
const entry = registry[filename];
if (entry) {
try {
const base64Data = await fileToBase64(entry.file);
exportData[filename] = {
data: base64Data,
type: entry.file.type,
size: entry.file.size,
uploadedAt: entry.uploadedAt.toISOString(),
};
} catch (error) {
console.warn(`Failed to export icon ${filename}:`, error);
}
}
}
}
})
);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This implementation mutates the exportData object from within concurrent map callbacks. This is an anti-pattern that introduces side effects into a map operation and can be prone to race conditions in more complex scenarios.

A cleaner, more functional approach is to have map return the data for each icon, and then build the final exportData object from the collected results. This avoids side effects and makes the code more predictable and maintainable.

    const entries = await Promise.all(
      targetFilenames.map(async (filename) => {
        const entry = registry[filename];
        if (entry) {
          try {
            const base64Data = await fileToBase64(entry.file);
            return [filename, {
              data: base64Data,
              type: entry.file.type,
              size: entry.file.size,
              uploadedAt: entry.uploadedAt.toISOString(),
            }];
          } catch (error) {
            console.warn(`Failed to export icon ${filename}:`, error);
          }
        }
        return null;
      })
    );

    const exportData: IconExportData = Object.fromEntries(entries.filter(entry => entry));
References
  1. Avoid side effects within functional operations. Perform calculations that produce values needed before calling the operation to maintain its purity and predictability.

@aafre
Copy link
Copy Markdown
Owner Author

aafre commented Apr 11, 2026

Closing: superseded by #421 (cleanest version). Cherry-picked into #457.

@aafre aafre closed this Apr 11, 2026
@google-labs-jules
Copy link
Copy Markdown
Contributor

Closing: superseded by #421 (cleanest version). Cherry-picked into #457.

Understood. Acknowledging that this work is superseded and cherry-picked into another PR. Stopping work on this task.

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