{"type":"queue-operation","operation":"dequeue","timestamp":"2026-01-11T22:33:18.114Z","sessionId":"7f989a70-a6e7-4fbe-92c0-6756e7497ba4"} {"parentUuid":null,"isSidechain":false,"userType":"external","cwd":"C:\\Users\\MikeSwanson\\claude-projects\\guru-connect","sessionId":"7f989a70-a6e7-4fbe-92c0-6756e7497ba4","version":"2.1.4","gitBranch":"main","type":"user","message":{"role":"user","content":"# Performance Optimizations Ideation Agent\n\nYou are a senior performance engineer. Your task is to analyze a codebase and identify performance bottlenecks, optimization opportunities, and efficiency improvements.\n\n## Context\n\nYou have access to:\n- Project index with file structure and dependencies\n- Source code for analysis\n- Package manifest with bundle dependencies\n- Database schemas and queries (if applicable)\n- Build configuration files\n- Memory context from previous sessions (if available)\n- Graph hints from Graphiti knowledge graph (if available)\n\n### Graph Hints Integration\n\nIf `graph_hints.json` exists and contains hints for your ideation type (`performance_optimizations`), use them to:\n1. **Avoid duplicates**: Don't suggest optimizations that have already been implemented\n2. **Build on success**: Prioritize optimization patterns that worked well in the past\n3. **Learn from failures**: Avoid optimizations that previously caused regressions\n4. **Leverage context**: Use historical profiling knowledge to identify high-impact areas\n\n## Your Mission\n\nIdentify performance opportunities across these categories:\n\n### 1. Bundle Size\n- Large dependencies that could be replaced\n- Unused exports and dead code\n- Missing tree-shaking opportunities\n- Duplicate dependencies\n- Client-side code that should be server-side\n- Unoptimized assets (images, fonts)\n\n### 2. Runtime Performance\n- Inefficient algorithms (O(n²) when O(n) possible)\n- Unnecessary computations in hot paths\n- Blocking operations on main thread\n- Missing memoization opportunities\n- Expensive regular expressions\n- Synchronous I/O operations\n\n### 3. Memory Usage\n- Memory leaks (event listeners, closures, timers)\n- Unbounded caches or collections\n- Large object retention\n- Missing cleanup in components\n- Inefficient data structures\n\n### 4. Database Performance\n- N+1 query problems\n- Missing indexes\n- Unoptimized queries\n- Over-fetching data\n- Missing query result limits\n- Inefficient joins\n\n### 5. Network Optimization\n- Missing request caching\n- Unnecessary API calls\n- Large payload sizes\n- Missing compression\n- Sequential requests that could be parallel\n- Missing prefetching\n\n### 6. Rendering Performance\n- Unnecessary re-renders\n- Missing React.memo / useMemo / useCallback\n- Large component trees\n- Missing virtualization for lists\n- Layout thrashing\n- Expensive CSS selectors\n\n### 7. Caching Opportunities\n- Repeated expensive computations\n- Cacheable API responses\n- Static asset caching\n- Build-time computation opportunities\n- Missing CDN usage\n\n## Analysis Process\n\n1. **Bundle Analysis**\n - Analyze package.json dependencies\n - Check for alternative lighter packages\n - Identify import patterns\n\n2. **Code Complexity**\n - Find nested loops and recursion\n - Identify hot paths (frequently called code)\n - Check algorithmic complexity\n\n3. **React/Component Analysis**\n - Find render patterns\n - Check prop drilling depth\n - Identify missing optimizations\n\n4. **Database Queries**\n - Analyze query patterns\n - Check for N+1 issues\n - Review index usage\n\n5. **Network Patterns**\n - Check API call patterns\n - Review payload sizes\n - Identify caching opportunities\n\n## Output Format\n\nWrite your findings to `{output_dir}/performance_optimizations_ideas.json`:\n\n```json\n{\n \"performance_optimizations\": [\n {\n \"id\": \"perf-001\",\n \"type\": \"performance_optimizations\",\n \"title\": \"Replace moment.js with date-fns for 90% bundle reduction\",\n \"description\": \"The project uses moment.js (300KB) for simple date formatting. date-fns is tree-shakeable and would reduce the date utility footprint to ~30KB.\",\n \"rationale\": \"moment.js is the largest dependency in the bundle and only 3 functions are used: format(), add(), and diff(). This is low-hanging fruit for bundle size reduction.\",\n \"category\": \"bundle_size\",\n \"impact\": \"high\",\n \"affectedAreas\": [\"src/utils/date.ts\", \"src/components/Calendar.tsx\", \"package.json\"],\n \"currentMetric\": \"Bundle includes 300KB for moment.js\",\n \"expectedImprovement\": \"~270KB reduction in bundle size, ~20% faster initial load\",\n \"implementation\": \"1. Install date-fns\\n2. Replace moment imports with date-fns equivalents\\n3. Update format strings to date-fns syntax\\n4. Remove moment.js dependency\",\n \"tradeoffs\": \"date-fns format strings differ from moment.js, requiring updates\",\n \"estimatedEffort\": \"small\"\n }\n ],\n \"metadata\": {\n \"totalBundleSize\": \"2.4MB\",\n \"largestDependencies\": [\"react-dom\", \"moment\", \"lodash\"],\n \"filesAnalyzed\": 145,\n \"potentialSavings\": \"~400KB\",\n \"generatedAt\": \"2024-12-11T10:00:00Z\"\n }\n}\n```\n\n## Impact Classification\n\n| Impact | Description | User Experience |\n|--------|-------------|-----------------|\n| high | Major improvement visible to users | Significantly faster load/interaction |\n| medium | Noticeable improvement | Moderately improved responsiveness |\n| low | Minor improvement | Subtle improvements, developer benefit |\n\n## Common Anti-Patterns\n\n### Bundle Size\n```javascript\n// BAD: Importing entire library\nimport _ from 'lodash';\n_.map(arr, fn);\n\n// GOOD: Import only what's needed\nimport map from 'lodash/map';\nmap(arr, fn);\n```\n\n### Runtime Performance\n```javascript\n// BAD: O(n²) when O(n) is possible\nusers.forEach(user => {\n const match = allPosts.find(p => p.userId === user.id);\n});\n\n// GOOD: O(n) with map lookup\nconst postsByUser = new Map(allPosts.map(p => [p.userId, p]));\nusers.forEach(user => {\n const match = postsByUser.get(user.id);\n});\n```\n\n### React Rendering\n```jsx\n// BAD: New function on every render\n