From d551f3aea32d50b5dc140127decdda8e0ee92390 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 5 Sep 2026 06:39:46 +0000 Subject: [PATCH] perf: optimize post-resolution search query response latency - Remove artificial 500ms delay in processResolutionSearch and processEvents - Stream query suggestions immediately on initial chunk and throttle subsequent updates at 100ms - Enhance cache key generation to handle complex array content safely Co-authored-by: ngoiyaeric <115367894+ngoiyaeric@users.noreply.github.com> --- app/actions.tsx | 4 ---- lib/agents/query-suggestor.tsx | 18 +++++++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/actions.tsx b/app/actions.tsx index 03beb14f..38abb85d 100644 --- a/app/actions.tsx +++ b/app/actions.tsx @@ -244,8 +244,6 @@ async function submit(formData?: FormData, skip?: boolean) { ); - await new Promise(resolve => setTimeout(resolve, 500)); - aiState.done({ ...aiState.get(), messages: [ @@ -579,8 +577,6 @@ async function submit(formData?: FormData, skip?: boolean) { ) - await new Promise(resolve => setTimeout(resolve, 500)) - aiState.done({ ...aiState.get(), messages: [ diff --git a/lib/agents/query-suggestor.tsx b/lib/agents/query-suggestor.tsx index b033054e..dbcaa503 100644 --- a/lib/agents/query-suggestor.tsx +++ b/lib/agents/query-suggestor.tsx @@ -20,7 +20,11 @@ function getCacheKey(messages: CoreMessage[]): string { const recentMessages = messages.slice(-3); return JSON.stringify(recentMessages.map(m => ({ role: m.role, - content: typeof m.content === 'string' ? m.content : '[complex content]' + content: typeof m.content === 'string' + ? m.content.slice(-500) + : Array.isArray(m.content) + ? m.content.map((p: any) => p?.text || '').join(' ').slice(-500) + : '[complex content]' }))); } @@ -74,20 +78,20 @@ export async function querySuggestor( return fallback } - // OPTIMIZATION: Stream updates but batch them to reduce re-render frequency - let lastUpdateTime = Date.now(); - const UPDATE_THROTTLE = 200; // ms + // OPTIMIZATION: Stream updates efficiently - update immediately on first item, then throttle + let lastUpdateTime = 0; + const UPDATE_THROTTLE = 100; // ms try { for await (const obj of result.partialObjectStream) { if (obj && typeof obj === 'object' && 'items' in obj) { + finalRelatedQueries = obj as PartialRelated const now = Date.now(); - // Only update UI if enough time has passed since last update - if (now - lastUpdateTime > UPDATE_THROTTLE) { + // Update UI immediately on first yield or after throttle interval + if (lastUpdateTime === 0 || now - lastUpdateTime > UPDATE_THROTTLE) { objectStream.update(obj as PartialRelated) lastUpdateTime = now; } - finalRelatedQueries = obj as PartialRelated } } } catch (error) {