- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10
Closed
Description
Problem
Current startup time is 6-13s (6s on M3, 13s on M1), primarily due to loading the entire AI SDK and all provider packages. We import the full SDK even though we only use specific providers.
Proposed Solution
Tree-shake AI SDK imports to only load what we actually use:
- Audit current usage - Determine which providers we actually need (likely just Anthropic)
- Use direct imports - Instead of importing from top-level packages, import specific modules
- Lazy-load unused providers - If we support multiple providers, load them on-demand
Example
// ❌ Current: Loads everything
import { anthropic } from '@ai-sdk/anthropic'
import { openai } from '@ai-sdk/openai'  // Loaded even if unused
// ✅ Optimized: Only load what's used
import { anthropic } from '@ai-sdk/anthropic'
// Don't import openai unless neededExpected Impact
- Reduce initial module parse time by 30-50%
- Target startup: 3-6s instead of 6-13s
- Simpler than worker threads or other complex approaches
- No UX tradeoffs - just loads less code
Context
This is a better long-term solution than worker threads (PR #226), which moved work to another core but didn't reduce total load time. Real performance gains come from loading less code in the first place.
Implementation Notes
- May require refactoring service initialization to be provider-specific
- Could add runtime provider loading if we support multiple backends
- Should audit all AI SDK imports across codebase
Related: PR #226 (splash screen improvements)
Metadata
Metadata
Assignees
Labels
No labels