Bundle Size
Grain is designed to be lightweight:- Core SDK: ~6 KB gzipped
- With React Hooks: ~8 KB gzipped
- Zero dependencies: No bloat
Batching Strategy
Events are automatically batched for efficiency:For High-Traffic Apps
Increase batch size to reduce request volume:For Real-Time Apps
Decrease batch size for faster delivery:For Serverless
Disable batching, flush manually:Configuration Caching
Remote config uses cache-first strategy for instant loading: How it works:- Return cached/default value immediately (0ms)
- Fetch fresh value in background
- Update cache when received
Refresh Interval
Control how often configs refresh:Disable Caching
For testing or specific scenarios:React Hooks Optimization
Hooks are optimized to prevent unnecessary re-renders:useConfig for specific values to minimize re-renders.
Track Function Memoization
useTrack returns a stable function reference:
track - already optimized.
Preloading Configurations
Preload configs at app startup for zero-delay access:Lazy Loading
Initialize Grain lazily if not needed immediately:Network Optimization
Retry Configuration
Balance reliability with performance:Beacon API
For page exit events, Beacon API ensures delivery:Memory Management
Events are queued in memory until sent. Large queues use more memory:Monitoring Performance
Enable debug mode to monitor performance:- Batch send times
- Queue sizes
- Network requests
- Retry attempts