This guide provides best practices for optimizing RecCall performance and understanding the performance characteristics of the system.
RecCall has been optimized for sub-millisecond operations with intelligent caching, batched I/O operations, and comprehensive performance monitoring.
Performance metrics are validated based on:
- Architecture Analysis: Documented baseline performance from Performance Analysis
- Optimization Implementation: LRU cache, write batching, MCP caching implementations
- Industry Benchmarks: Standard expectations for similar caching and I/O optimizations
- Cache Architecture: Multi-layer caching with automatic eviction patterns
Note: Actual performance depends on:
- Cache configuration (size, TTL)
- Workload patterns
- System resources (CPU, memory, disk I/O)
- Cache hit rates
- System load and concurrent operations
Performance metrics quoted in documentation and website are based on these validated architectural improvements.
| Operation | Cold Start | Cached | Notes |
|---|---|---|---|
| rec command | 50-100ms | <1ms | Includes validation + batched write |
| call command | 30-80ms | <1ms | Instant with cache hit |
| list command | 80ms | <10ms | Linear with shortcut count (cached) |
| search command | 30-80ms | <10ms | In-memory filtering |
| update command | 50-100ms | <1ms | Similar to rec (cached) |
| delete command | 50-100ms | <1ms | Idempotent operation (cached) |
| Metric | Baseline | Optimized | Improvement |
|---|---|---|---|
| MCP server overhead | 10-50ms | <5ms | Tools list cached (1 min TTL) |
| Repository operations | 200-500ms | <100ms (network) / <10ms (cached) | HTTP caching + repository cache |
| Cache hit rate | N/A | >95% | For typical workloads with warm cache |
| Write batching efficiency | N/A | 90% reduction | Multiple writes within 50ms window |
Based on Performance Analysis:
Before Optimizations:
- File I/O on every operation (10-100ms per operation)
- No caching system
- Synchronous blocking operations
- Higher MCP overhead
After Optimizations:
- ✅ LRU cache with sub-millisecond cached operations
- ✅ Batched writes reduce I/O by 90%
- ✅ Multi-layer caching (memory + disk)
- ✅ MCP tools list caching
- ✅ Comprehensive performance monitoring
Result: 50-100x faster for cached operations, 8x faster for list operations, 2-10x reduction in MCP overhead.
RecCall uses a sophisticated multi-layer caching system:
- Memory Cache (L1): LRU cache with configurable TTL and max size
- Disk Cache (L2): Persistent cache for cold starts
- Automatic Eviction: Least recently used items are evicted when cache is full
// Cache configuration
const cacheManager = new MultiLayerCacheManager({
maxSize: 1000, // Maximum cache entries
ttl: 3600000, // 1 hour default TTL
updateAgeOnGet: true // Refresh TTL on access
});File writes are automatically batched to reduce I/O overhead:
- Write Batching: Multiple writes within 50ms are batched
- Atomic Writes: All writes use atomic rename operations
- Cache-First: Updates happen in-memory immediately, writes are queued
// Multiple writes are automatically batched
await storage.record('shortcut1', 'context1');
await storage.record('shortcut2', 'context2');
await storage.record('shortcut3', 'context3');
// Only one disk write occursComprehensive performance monitoring is built-in:
import { telemetryManager } from 'reccall/core';
// Get performance metrics
const metrics = telemetryManager.getMetrics();
console.log({
averageResponseTime: metrics.averageResponseTime,
operationCounts: metrics.operationCounts,
cacheHitRate: metrics.cacheHitRate,
fileIOOperations: metrics.fileIOOperations
});Warm up the cache on application startup:
const engine = await createCoreEngine();
await engine.initialize();
// Pre-load commonly used shortcuts
const shortcuts = await engine.list();
// Cache is now warm and subsequent operations will be fastWhen recording multiple shortcuts, batch them:
// Good: Sequential batch writes
await engine.record('shortcut1', 'context1');
await engine.record('shortcut2', 'context2');
await engine.record('shortcut3', 'context3');
// Writes are automatically batched
// Better: Parallel operations with batched writes
await Promise.all([
engine.record('shortcut1', 'context1'),
engine.record('shortcut2', 'context2'),
engine.record('shortcut3', 'context3')
]);Adjust cache size based on your workload:
// For applications with many shortcuts
const cacheManager = new MultiLayerCacheManager(5000); // 5000 entries
// For memory-constrained environments
const cacheManager = new MultiLayerCacheManager(100); // 100 entriesConfigure TTL based on data freshness requirements:
// Short TTL for frequently changing data
configManager.setCacheTtl(60000); // 1 minute
// Long TTL for stable data
configManager.setCacheTtl(3600000); // 1 hourUse the built-in benchmarking suite to measure performance:
# Run comprehensive benchmarks
npm run benchmark
# Or use the script directly
node scripts/benchmark.tsThe benchmark suite measures:
- Average response time: Mean of all operations
- Percentiles: P50, P95, P99 response times
- Cache performance: Hit rates and miss rates
- Per-operation metrics: Individual command performance
- Throughput: Operations per second
📊 Benchmark Results
===================
✅ Successful Operations:
🚀 call cached: 0.45ms
🚀 call cached: 0.52ms
⚡ list: 8.32ms
📈 Performance Summary:
Average: 2.15ms
Minimum: 0.45ms
Maximum: 8.32ms
P50 (median): 0.52ms
P95: 8.32ms
P99: 8.32ms
🎯 Performance Targets:
Sub-millisecond (<1ms): 2/3 (66.7%)
Sub-10ms (<10ms): 3/3 (100.0%)
📊 Performance by Command:
call: avg=0.48ms, min=0.45ms, max=0.52ms (2 operations)
list: avg=8.32ms, min=8.32ms, max=8.32ms (1 operations)
Enable telemetry to monitor production performance:
import { telemetryManager } from 'reccall/core';
// Export Prometheus metrics
const metrics = telemetryManager.exportPrometheusMetrics();
console.log(metrics);Use the @Performance decorator to monitor specific operations:
import { Performance } from 'reccall/core';
class MyService {
@Performance('my-operation')
async myOperation() {
// Automatically monitored
}
}Analyze structured logs for performance insights:
// Logs include performance metrics
telemetryManager.logEvent({
event: 'operation.completed',
duration: 1.2,
properties: {
operation: 'record',
cacheHit: true
}
});- Check cache hit rate: Low hit rates indicate cache configuration issues
- Monitor file I/O: High file I/O counts suggest batching isn't working
- Review telemetry: Check operation counts and error rates
- Reduce cache size: Lower
maxSizeparameter - Shorter TTL: More frequent evictions
- Monitor cache stats: Use
getStats()to see cache utilization
- Enable write batching: Already enabled by default
- Use faster storage: SSD instead of HDD
- Consider Redis/PostgreSQL: For high-throughput scenarios
For high-performance scenarios, use Redis or PostgreSQL:
import { RedisStorage } from 'reccall/storage-backends/redis';
const storage = new RedisStorage({
url: 'redis://localhost:6379',
keyPrefix: 'reccall:',
ttl: 3600
});For repository operations, implement connection pooling:
// Repository client can be configured with connection pooling
const repository = new HttpRepositoryClient({
poolSize: 10,
timeout: 5000
});Pre-fetch likely-to-be-used shortcuts:
// Predict and pre-fetch based on usage patterns
const likelyShortcuts = await analyzeUsagePatterns();
await Promise.all(
likelyShortcuts.map(id => engine.call(id))
);Set up monitoring using Prometheus and Grafana:
// Export metrics endpoint
app.get('/metrics', (req, res) => {
res.set('Content-Type', 'text/plain');
res.send(telemetryManager.exportPrometheusMetrics());
});RecCall is optimized for performance with:
- ✅ Sub-millisecond cached operations
- ✅ Intelligent multi-layer caching
- ✅ Batched I/O operations
- ✅ Comprehensive performance monitoring
- ✅ Automatic cache eviction
- ✅ Detailed benchmarking suite
Follow this guide to maximize RecCall's performance in your environment.