Skip to content

⚡ Bolt: Use Promise.all for concurrent file reading in icon export#494

Closed
aafre wants to merge 1 commit into
mainfrom
perf/concurrent-icon-export-15608440110130733370
Closed

⚡ Bolt: Use Promise.all for concurrent file reading in icon export#494
aafre wants to merge 1 commit into
mainfrom
perf/concurrent-icon-export-15608440110130733370

Conversation

@aafre
Copy link
Copy Markdown
Owner

@aafre aafre commented Apr 24, 2026

💡 What: Replaced a sequential await loop with Promise.all in exportIconsForYAML inside useIconRegistry.ts.
🎯 Why: Reading multiple files sequentially blocks execution unnecessarily. Concurrent reads are much faster.
📊 Impact: Significantly reduces total export time when processing multiple icon files by utilizing parallel FileReader conversions.
🔬 Measurement: Observe faster YAML exports when multiple icons are in the registry.


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

Replaced a sequential `await` loop with `Promise.all` in `exportIconsForYAML` inside `useIconRegistry.ts`.

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.

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 icon export process in useIconRegistry.ts by refactoring sequential file read operations into concurrent execution using Promise.all. A review comment suggests improving the implementation by avoiding shared state mutation within the concurrent tasks to ensure deterministic key ordering and more idiomatic code.

Comment on lines 170 to +193
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: Process FileReader conversions concurrently
// Replaced sequential await in loop with Promise.all to significantly reduce
// total export time when processing multiple icon files, while preserving
// individual error handling.
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

While using Promise.all correctly introduces concurrency, mutating a shared object (exportData) from within concurrent promises can lead to non-deterministic key ordering in the resulting object. This happens because the order of keys in the final object will depend on the completion order of the asynchronous fileToBase64 calls.

A more idiomatic and robust approach is to have the promises return the data and then assemble the object using Object.fromEntries. This ensures that the order of keys in the exported data remains consistent with the order in targetFilenames (which is deterministic) and avoids side effects inside the concurrent tasks.

References
  1. Avoid mutating shared state from within concurrent asynchronous operations to prevent race conditions and ensure deterministic behavior.

@aafre
Copy link
Copy Markdown
Owner Author

aafre commented May 25, 2026

Closing duplicate — the most recent version of this change is PR #535.

@aafre aafre closed this May 25, 2026
@google-labs-jules
Copy link
Copy Markdown
Contributor

Closing duplicate — the most recent version of this change is PR #535.

Understood. Acknowledging that this work is a duplicate and 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