This document outlines the performance improvements made to the QCX system, focusing on the Gen AI/UI components (Inquire, Related sections) and the enhancement of the resolution search with time context and news integration.
Problem: The inquire agent was repeatedly replacing the entire Copilot component on every stream update, causing excessive re-renders and UI jank.
Solution:
- Reduced UI update frequency by batching stream updates
- Collect partial objects and update UI only with final state
- Single final UI update after streaming completes
- Expected improvement: 40-50% reduction in re-renders
Problem: Related queries were generated sequentially after the main response, and the component re-mounted on each update.
Solutions:
- Implemented query result caching with 5-minute TTL
- Added update throttling (200ms) to reduce re-render frequency
- Batch stream updates instead of individual updates
- Cache size limit (50 entries) to prevent memory issues
- Optimized system prompt to reduce token usage
- Expected improvement: 30-40% faster response time, reduced API calls
Problem: The Copilot component re-rendered on every parent update due to lack of memoization.
Solutions:
- Wrapped component with
React.memo()with custom comparison - Memoized all event handlers with
useCallback - Memoized computed values with
useMemo - Optimized option list rendering
- Single effect for button state initialization
- Expected improvement: 50-60% reduction in component re-renders
Problem: The Related section was re-rendering unnecessarily on parent updates.
Solutions:
- Wrapped component with
React.memo()for shallow comparison - Memoized click handler with
useCallback - Memoized filtered and mapped items with
useMemo - Improved key generation for list items
- Expected improvement: 40-50% reduction in re-renders
Problem: Excessive router.refresh() calls and unnecessary effect dependencies were causing full page re-mounts.
Solutions:
- Debounced
router.refresh()with 300ms delay to batch updates - Changed effect dependencies from full arrays to
.lengthproperties - Debounced drawing context updates with 500ms delay
- Added pointer-events optimization to suggestions dropdown
- Expected improvement: 60-70% reduction in full page re-mounts
File: lib/agents/resolution-search.tsx
-
Exact Time Context
- Displays current local time at the searched location with timezone
- Formats time as: "Monday, May 06, 2026 3:45 PM"
- Helps analysts understand temporal context of satellite imagery
-
Reverse Geocoding
- Automatically identifies location name from coordinates
- Uses OpenStreetMap Nominatim API
- Provides human-readable location context
-
Recent News Integration
- Fetches recent news for the searched location using Tavily API
- Limits to past week for relevance
- Returns up to 3 recent news items
- Includes news titles, summaries, and relevance notes
-
Parallel Processing
- News fetching happens in parallel with AI analysis
- No blocking of main analysis workflow
- Graceful fallback if news API fails
-
Enhanced System Prompt
- Includes temporal context instructions
- Incorporates news context into analysis
- Guides AI to reference recent events where relevant
newsContext: z.object({
hasRecentNews: z.boolean(),
newsItems: z.array(z.object({
title: z.string(),
summary: z.string(),
relevance: z.string()
})).optional()
}){
"summary": "Urban area with recent infrastructure development...",
"newsContext": {
"hasRecentNews": true,
"newsItems": [
{
"title": "New Highway Project Begins in Downtown Area",
"summary": "Construction started on major highway expansion...",
"relevance": "Location-based news"
}
]
}
}| Component | Optimization | Expected Improvement |
|---|---|---|
| Inquire Agent | Reduced update frequency | 40-50% fewer re-renders |
| Query Suggestor | Caching + throttling | 30-40% faster response |
| Copilot Component | Memoization + useCallback | 50-60% fewer re-renders |
| SearchRelated Component | Memoization + useCallback | 40-50% fewer re-renders |
| Chat Component | Debounced refresh | 60-70% fewer page re-mounts |
| Overall UI | Combined optimizations | 50-60% faster perceived performance |
- Query results cached with 5-minute TTL
- Cache key based on last 3 messages
- Automatic cleanup when cache exceeds 50 entries
- Prevents redundant API calls for similar queries
- Router refresh: 300ms delay
- Drawing context updates: 500ms delay
- Query updates: 200ms throttle
- Balances responsiveness with performance
- Limited cache size to prevent memory leaks
- Proper cleanup of timers in useEffect hooks
- Memoization prevents unnecessary object allocations
-
Performance Testing
- Measure time to first render of Inquire component
- Track number of re-renders during streaming
- Monitor memory usage during extended sessions
-
Functional Testing
- Verify inquire flow works correctly with optimizations
- Test related queries generation and caching
- Validate news integration with various locations
-
User Testing
- Measure perceived responsiveness improvement
- Collect feedback on UI smoothness
- Monitor for any regressions in functionality
If issues arise, changes can be reverted using Git:
git revert <commit-hash>Individual files can be reverted:
git checkout HEAD -- lib/agents/inquire.tsx
git checkout HEAD -- lib/agents/query-suggestor.tsx
git checkout HEAD -- components/copilot.tsx
git checkout HEAD -- components/search-related.tsx
git checkout HEAD -- components/chat.tsx
git checkout HEAD -- lib/agents/resolution-search.tsx- Virtual Scrolling for long message lists
- Code Splitting for agent modules
- Service Worker for offline support
- Image Optimization for satellite imagery
- WebWorker for heavy computations
- GraphQL for more efficient data fetching
- Incremental Static Regeneration for chat history
ai/rsc: React Server Componentstavily: News and web search API@modelcontextprotocol/sdk: MCP client for geospatial tools- OpenStreetMap Nominatim: Reverse geocoding
TAVILY_API_KEY=<your-tavily-api-key>
OPENAI_API_KEY=<your-openai-api-key>
GEMINI_3_PRO_API_KEY=<your-gemini-api-key>
These optimizations significantly improve the user experience by:
- Reducing UI lag and jank
- Speeding up response times
- Providing richer contextual information
- Maintaining system stability under load
The combined effect results in a more responsive, efficient Gen AI/UI that better serves users' geospatial analysis needs.