Performance Tuning Guide
This guide covers performance optimization strategies for TealTiger v1.1.0 to ensure minimal latency and efficient resource usage.Performance Targets
TealTiger is designed to add minimal overhead to your AI workflows:| Metric | Target | Typical |
|---|---|---|
| Policy evaluation | under 10ms (p95) | 2-5ms |
| Audit event write | under 5ms (p95) | 1-3ms |
| Memory overhead | under 50MB | 20-30MB |
| Cold start | under 50ms | 20-30ms |
Policy Evaluation Optimization
Simplify Policy Structure
Complex nested policies increase evaluation time. Keep policies flat and simple: ❌ Slow:Use Direct Lookups
Direct property lookups are faster than pattern matching: ❌ Slow:Minimize Context Size
Only include necessary fields in ExecutionContext: ❌ Slow:Cache Policy Engines
Reuse TealEngine instances instead of creating new ones: ❌ Slow:Audit Logging Optimization
Configure Buffer Size
Batch audit events to reduce I/O operations:- High throughput: Increase buffer_size (500-1000)
- Low latency: Decrease buffer_size (10-50)
- Balanced: 100-200 events
Use Async Writes
Enable async writes to avoid blocking the main thread:Optimize Output Destinations
Choose appropriate output destinations based on performance requirements:| Output | Latency | Throughput | Use Case |
|---|---|---|---|
| Memory | under 1ms | Very High | Testing, temporary storage |
| File | 1-3ms | High | Local development, single server |
| Syslog | 5-10ms | Medium | Centralized logging |
| HTTP | 10-50ms | Medium | Cloud logging services |
| S3 | 50-200ms | Low | Long-term archival |
Reduce Redaction Overhead
Redaction adds processing time. Choose appropriate levels:| Redaction Level | Overhead | Security |
|---|---|---|
| NONE | 0ms | ❌ Low |
| PARTIAL | 1-2ms | ⚠️ Medium |
| HASH | 2-3ms | ✅ High |
| REMOVE | under 1ms | ✅ Maximum |
REMOVE for maximum performance and security:
Memory Optimization
Limit Audit Buffer Size
Prevent memory growth by limiting buffer size:Release Context Objects
Release ExecutionContext objects when done:Monitor Memory Usage
Track memory usage in production:Async Patterns
Use Async Evaluation
For I/O-bound operations, use async evaluation:Batch Evaluations
Evaluate multiple requests in parallel:Stream Processing
For high-throughput scenarios, use streaming:Caching Strategies
Cache Policy Decisions
Cache decisions for identical requests:Cache Policy Engines
For multi-tenant scenarios, cache engines per tenant:Serverless Optimization
Minimize Cold Start Time
Optimize for serverless cold starts:Use Provisioned Concurrency
For AWS Lambda, use provisioned concurrency to keep instances warm:Optimize Bundle Size
Reduce bundle size to improve cold start:Monitoring and Profiling
Enable Performance Metrics
Track performance metrics in production:Profile in Development
Use Node.js profiler to identify bottlenecks:Benchmark Changes
Benchmark before and after optimization:Production Checklist
Before deploying to production:- Policy structure simplified (flat, direct lookups)
- Context size minimized (only necessary fields)
- TealEngine instances cached and reused
- Audit buffer size configured appropriately
- Async writes enabled for audit outputs
- Redaction level optimized (REMOVE for best performance)
- Memory limits configured
- Async evaluation used for I/O-bound operations
- Caching strategy implemented (if applicable)
- Performance metrics enabled
- Benchmarks run and targets met
Performance Troubleshooting
High Latency
If policy evaluation is slow (>10ms):- Profile the code: Identify bottlenecks
- Simplify policies: Remove complex nested conditions
- Reduce context size: Only include necessary fields
- Check for blocking I/O: Use async evaluation
- Enable caching: Cache decisions for identical requests
High Memory Usage
If memory usage is high (>100MB):- Reduce buffer size: Lower audit buffer limits
- Flush more frequently: Decrease flush interval
- Release contexts: Explicitly release ExecutionContext objects
- Check for leaks: Use heap profiler to find leaks
- Limit cache size: Set max size for LRU caches
Low Throughput
If throughput is low (under 1000 req/s):- Use async evaluation: Enable non-blocking operations
- Batch operations: Process multiple requests in parallel
- Optimize audit writes: Use async writes and larger buffers
- Scale horizontally: Add more instances
- Use streaming: Process requests as streams

