Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 2026-05-05 - Parallelize independent async file operations
**Learning:** Sequential `await` in loops over independent asynchronous file operations (like `FileReader` conversions in `useIconRegistry`) creates significant unnecessary delays. JavaScript's single-threaded nature allows `Promise.all` to safely map distinct keys on a shared object concurrently without race conditions.
**Action:** Refactor sequential asynchronous tasks in loops into concurrent operations using `Promise.all`, while ensuring individual error handling remains intact.
33 changes: 18 additions & 15 deletions resume-builder-ui/src/hooks/useIconRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,22 +169,25 @@ export const useIconRegistry = (): UseIconRegistryReturn => {
const targetFilenames = filenames || Object.keys(registry);
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);
// Use Promise.all to parallelize asynchronous file-to-base64 conversions
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);
}
}
}
}
})
);

return exportData;
}, [registry, fileToBase64]);
Expand Down
Loading