⚡ Bolt: Optimize icon export performance with concurrent processing#490
⚡ Bolt: Optimize icon export performance with concurrent processing#490aafre wants to merge 1 commit into
Conversation
Co-authored-by: aafre <8656674+aafre@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request refactors the icon export logic in useIconRegistry.ts to use Promise.all for concurrent file processing, significantly improving performance. A new documentation entry was also added to .jules/bolt.md. Feedback was provided to deduplicate input filenames using a Set and to ensure deterministic output ordering to prevent unnecessary diff noise in version-controlled files.
| // ⚡ Bolt: Performance Optimization | ||
| // Run all FileReader conversions concurrently using Promise.all | ||
| // instead of sequentially awaiting each one in a for...of loop. | ||
| 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| ); |
There was a problem hiding this comment.
The current implementation populates exportData concurrently, which makes the order of keys non-deterministic. For version-controlled files like JSON/YAML, this creates unnecessary diff noise. Additionally, to prevent redundant processing if the filenames argument contains duplicates, deduplicate the input using a Set before processing. This ensures each file is converted only once and maintains a consistent output structure.
const uniqueFilenames = [...new Set(targetFilenames)];
const results = await Promise.all(
uniqueFilenames.map(async (filename) => {
const entry = registry[filename];
if (!entry) return null;
try {
const base64Data = await fileToBase64(entry.file);
return {
filename,
item: {
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;
}
})
);
results.forEach((res) => {
if (res) exportData[res.filename] = res.item;
});References
- Prefer using efficient data structures like Set or Map for handling collections and lookups to avoid O(n) complexity or redundant processing.
|
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. |
💡 What: Refactored sequential
awaitinexportIconsForYAMLto concurrent processing usingPromise.all.🎯 Why: The previous implementation exported files sequentially, introducing unnecessary I/O bottleneck when exporting multiple icons.
📊 Impact: Reduces export execution time from O(N) to O(1) in the number of concurrent I/O operations, making exports significantly faster when multiple icons are present.
🔬 Measurement: Profile
exportIconsForYAMLwith several icons uploaded. The function should execute faster by resolving conversions in parallel.PR created automatically by Jules for task 2392848187885635351 started by @aafre