From 8149d4ad2abd60e942ffa7a7558dacba5a313955 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 16 May 2026 17:22:34 +0000 Subject: [PATCH] perf(models): concurrent ZimaOS gateway fetch Optimized the network fetching of ZimaOS models to initiate the requests concurrently instead of awaiting them sequentially inside the loop, while preserving the stateful side effects. Co-authored-by: bobdivx <6737167+bobdivx@users.noreply.github.com> --- .jules/bolt.md | 3 +++ src/lib/forge-openai-surface.ts | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 00000000..baaba20c --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-18 - Optimize Stateful Sequential Iteration Over Network I/O +**Learning:** Sequential network calls inside a `for...of` loop can become a significant bottleneck when querying multiple endpoints or paths, especially when the calls are independent. +**Action:** Use `Promise.all` to fetch all resources concurrently. To preserve side-effect logic dependent on order (like keeping the "last" status or error), store the resolved promises in an array and iterate over them sequentially in the same order as the original paths array. diff --git a/src/lib/forge-openai-surface.ts b/src/lib/forge-openai-surface.ts index 93415262..afef3464 100644 --- a/src/lib/forge-openai-surface.ts +++ b/src/lib/forge-openai-surface.ts @@ -118,8 +118,13 @@ export async function collectZimaOSV1ModelEntries( let lastError: string | undefined; let lastRaw: unknown = null; - for (const path of V1_MODELS_PATHS) { - const r = await fetchZimaOSJson(email, path); + // ⚡ Bolt: Initiate all network requests concurrently to avoid sequential network delays. + // We don't await Promise.all so we process them individually as they arrive + // while preserving the original stateful fallback resolution logic. + const fetches = V1_MODELS_PATHS.map((path) => fetchZimaOSJson(email, path)); + + for (const p of fetches) { + const r = await p; lastStatus = r.status; lastError = r.error; lastRaw = r.data;