@logistically/i18n-cli
Version:
Enterprise-grade CLI tool for extracting and managing translations in Logistically microservices
625 lines (458 loc) β’ 14.8 kB
Markdown
> Complete performance optimization guide for @logistically/i18n-cli
1. [Overview](
2. [Performance Features](
3. [Optimization Techniques](
4. [Monitoring & Metrics](
5. [Concurrent Processing](
6. [Memory Management](
7. [File Size Optimization](
8. [Best Practices](
9. [Performance Testing](
The CLI is designed for high-performance processing of large codebases with enterprise-grade optimization features. Performance is optimized at every level, from concurrent file processing to memory management.
1. **Concurrent Processing** - Parallel file processing for maximum throughput
2. **Memory Management** - Efficient memory usage with automatic cleanup
3. **File Size Filtering** - Skip large files to maintain performance
4. **Progress Tracking** - Real-time progress monitoring with ETA
5. **Performance Metrics** - Detailed performance analytics
6. **Batch Processing** - Process files in optimized batches
```
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Input Queue βββββΆβ Worker Pool βββββΆβ Output Queue β
β β β (Concurrent) β β β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
βΌ βΌ βΌ
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β File Filter β β Memory Pool β β Progress Bar β
β (Size/Type) β β (Optimized) β β (Real-time) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
```
Process multiple files simultaneously for maximum throughput.
```bash
i18n extract --concurrency 8
MAX_CONCURRENCY=8 i18n extract
i18n extract --auto-concurrency
```
```typescript
// Optimal concurrency based on CPU cores
const optimalConcurrency = Math.min(
require('os').cpus().length,
maxConcurrency
);
// Process files in batches
const batchSize = optimalConcurrency;
for (let i = 0; i < files.length; i += batchSize) {
const batch = files.slice(i, i + batchSize);
await Promise.allSettled(batch.map(processFile));
}
```
Skip files that are too large to process efficiently.
```bash
i18n extract --max-file-size 50
MAX_FILE_SIZE=50 i18n extract
i18n extract --auto-skip-large
```
```typescript
// Check file size before processing
const fileSize = await getFileSize(filePath);
const maxSize = config.performance.maxFileSize * 1024 * 1024; // MB to bytes
if (fileSize > maxSize) {
logger.warning(`Skipping large file: ${filePath} (${fileSize} bytes)`);
return;
}
```
Efficient memory usage with automatic cleanup.
```bash
i18n extract --monitor-memory
i18n extract --max-memory 512
MAX_MEMORY=512 i18n extract
```
```typescript
// Monitor memory usage
const memoryUsage = process.memoryUsage();
const heapUsedMB = memoryUsage.heapUsed / 1024 / 1024;
if (heapUsedMB > maxMemoryMB) {
logger.warning(`High memory usage: ${heapUsedMB.toFixed(2)}MB`);
// Trigger garbage collection or reduce concurrency
}
```
Real-time progress monitoring with speed and ETA.
```bash
i18n extract --progress-bar
ENABLE_PROGRESS_BAR=true i18n extract
i18n extract --progress-details
```
```typescript
// Update progress in real-time
const updateProgress = (current: number, total: number) => {
const percentage = Math.round((current / total) * 100);
const speed = current / (Date.now() - startTime) * 1000; // files/sec
const eta = (total - current) / speed; // seconds
logger.progress(`${current}/${total} (${percentage}%) - Speed: ${speed.toFixed(2)} files/sec - ETA: ${eta.toFixed(0)}s`);
};
```
Track detailed performance metrics:
```bash
i18n extract --monitor-performance
i18n extract --performance-report
i18n extract --export-performance
```
```typescript
interface PerformanceMetrics {
duration: number; // Duration in milliseconds
filesProcessed: number; // Number of files processed
totalKeys: number; // Total keys extracted
memoryUsage: number; // Memory usage in MB
cpuUsage: number; // CPU usage in seconds
speed: number; // Files per second
eta: number; // Estimated time remaining
}
```
Monitor performance in real-time:
```bash
i18n extract --monitor-performance --dashboard
i18n extract --performance-events
i18n extract --performance-report --format json
```
```typescript
// Performance dashboard
const dashboard = {
current: {
filesProcessed: 25,
keysExtracted: 150,
memoryUsage: 45.2,
speed: 2.5
},
total: {
files: 100,
keys: 500,
duration: 120000
},
performance: {
efficiency: 85.5,
throughput: 2.5,
memoryEfficiency: 90.2
}
};
```
Efficient worker pool for concurrent processing:
```typescript
// Create worker pool
const workerPool = new WorkerPool({
size: config.performance.maxConcurrency,
timeout: config.performance.timeout
});
// Process files concurrently
const results = await workerPool.process(files, async (file) => {
return await processFile(file);
});
```
Process files in optimized batches:
```typescript
// Process files in batches
const batchSize = Math.min(concurrency, 10);
const batches = chunk(files, batchSize);
for (const batch of batches) {
const batchResults = await Promise.allSettled(
batch.map(file => processFile(file))
);
// Update progress
updateProgress(processedFiles, totalFiles);
}
```
Optimize concurrency based on system resources:
```typescript
// Calculate optimal concurrency
const calculateOptimalConcurrency = () => {
const cpuCores = require('os').cpus().length;
const memoryGB = require('os').totalmem() / 1024 / 1024 / 1024;
// Base concurrency on CPU cores
let optimal = cpuCores;
// Adjust based on available memory
if (memoryGB < 4) optimal = Math.min(optimal, 2);
if (memoryGB < 8) optimal = Math.min(optimal, 4);
return Math.min(optimal, 20); // Max 20 concurrent processes
};
```
Efficient memory pool for file processing:
```typescript
// Memory pool for file content
class MemoryPool {
private pool: Buffer[] = [];
private maxSize: number;
constructor(maxSize: number) {
this.maxSize = maxSize;
}
acquire(size: number): Buffer {
const buffer = this.pool.find(b => b.length >= size);
if (buffer) {
this.pool = this.pool.filter(b => b !== buffer);
return buffer;
}
return Buffer.alloc(size);
}
release(buffer: Buffer): void {
if (this.pool.length < this.maxSize) {
this.pool.push(buffer);
}
}
}
```
Automatic garbage collection for memory optimization:
```typescript
// Trigger garbage collection when memory usage is high
const checkMemoryUsage = () => {
const memoryUsage = process.memoryUsage();
const heapUsedMB = memoryUsage.heapUsed / 1024 / 1024;
if (heapUsedMB > config.performance.maxMemory * 0.8) {
if (global.gc) {
global.gc();
logger.debug('Garbage collection triggered', 'performance');
}
}
};
```
Monitor memory usage in real-time:
```typescript
// Memory monitoring
const monitorMemory = () => {
const memoryUsage = process.memoryUsage();
return {
heapUsed: memoryUsage.heapUsed / 1024 / 1024,
heapTotal: memoryUsage.heapTotal / 1024 / 1024,
external: memoryUsage.external / 1024 / 1024,
rss: memoryUsage.rss / 1024 / 1024
};
};
```
Skip files that are too large to process efficiently:
```typescript
// File size filtering
const shouldProcessFile = async (filePath: string): Promise<boolean> => {
try {
const stats = await fs.stat(filePath);
const fileSizeMB = stats.size / 1024 / 1024;
if (fileSizeMB > config.performance.maxFileSize) {
logger.warning(`Skipping large file: ${filePath} (${fileSizeMB.toFixed(2)}MB)`);
return false;
}
return true;
} catch (error) {
logger.error(`Error checking file size: ${filePath}`, 'performance');
return false;
}
};
```
Handle large files efficiently:
```typescript
// Stream processing for large files
const processLargeFile = async (filePath: string): Promise<TranslationKey[]> => {
const stream = fs.createReadStream(filePath, { encoding: 'utf8' });
const chunks: string[] = [];
return new Promise((resolve, reject) => {
stream.on('data', (chunk) => {
chunks.push(chunk);
});
stream.on('end', () => {
const content = chunks.join('');
const keys = extractKeys(content);
resolve(keys);
});
stream.on('error', reject);
});
};
```
Set optimal concurrency based on your system:
```bash
i18n extract --concurrency 16
i18n extract --concurrency 2
i18n extract --auto-optimize
```
Always monitor performance in production:
```bash
i18n extract --monitor-performance --log-performance
i18n extract --performance-alerts --alert-threshold 80
```
Optimize file processing for your use case:
```bash
i18n extract --max-file-size 25
i18n extract --patterns "*.ts,*.js" --ignore "*.min.js"
i18n extract --batch-size 100
```
Optimize memory usage for large projects:
```bash
i18n extract --max-memory 512
i18n extract --monitor-memory --memory-alerts
i18n extract --stream-large-files
```
Use progress tracking for better user experience:
```bash
i18n extract --progress-bar
i18n extract --progress-details --show-speed --show-eta
i18n extract --log-progress --progress-file progress.log
```
Run comprehensive performance tests:
```bash
npm run performance:test
npm run performance:benchmark
npm run performance:stress-test
```
Benchmark different configurations:
```bash
i18n extract --benchmark-concurrency
i18n extract --benchmark-file-size
i18n extract --benchmark-memory
```
Profile performance for optimization:
```bash
i18n extract --profile-performance
i18n extract --performance-profile
i18n extract --analyze-performance
```
Track these key metrics:
1. **Throughput** - Files processed per second
2. **Memory Efficiency** - Memory usage per file
3. **CPU Utilization** - CPU usage during processing
4. **I/O Performance** - File read/write performance
5. **Concurrency Efficiency** - Optimal concurrency level
Generate detailed performance reports:
```bash
i18n extract --performance-report --format json
i18n extract --export-performance --output performance.json
i18n extract --performance-dashboard --port 3000
```
Set up performance alerts:
```bash
i18n extract --performance-thresholds "throughput:10,memory:80,cpu:90"
i18n extract --performance-alerts --alert-email performance@company.com
i18n extract --monitor-performance --alert-on-threshold
```
```bash
export MAX_CONCURRENCY=8
export MAX_FILE_SIZE=50
export MAX_MEMORY=512
export TIMEOUT=600
export ENABLE_PROGRESS_BAR=true
export MONITOR_PERFORMANCE=true
```
```json
{
"performance": {
"maxConcurrency": 8,
"maxFileSize": 50,
"maxMemory": 512,
"timeout": 600,
"enableProgressBar": true,
"monitorPerformance": true,
"autoOptimize": true,
"batchSize": 100
}
}
```
```bash
i18n extract --concurrency 8 --max-file-size 50 --max-memory 512
i18n extract --monitor-performance --progress-bar --performance-report
i18n extract --auto-optimize --stream-large-files --batch-processing
```
---
**For more information, see the [User Guide](./USER_GUIDE.md) or [Configuration Guide](./CONFIGURATION.md).**